Tabnine Logo
Menu
Code IndexAdd Tabnine to your IDE (free)

How to use
Menu
in
java.awt

Best Java code snippets using java.awt.Menu (Showing top 20 results out of 684)

Refine searchRefine arrow

  • MenuItem
  • MenuItem
  • MenuBar
  • MenuInflater
  • PopupMenu
  • Menus
  • SystemTray
  • TrayIcon
  • Stage
origin: stackoverflow.com

 private static final int MENU_ITEM_ITEM1 = 1;
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menu.add(Menu.NONE, MENU_ITEM_ITEM1, Menu.NONE, "Item name");
  return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
  case MENU_ITEM_ITEM1:
    clearArray();
    return true;

  default:
    return false;
 }
}
origin: wildfly/wildfly

private MenuBar createMenuBar() {
  MenuBar ret=new MenuBar();
  Menu file=new Menu("File");
  MenuItem quitm=new MenuItem("Quit");
  ret.setFont(def_font2);
  ret.add(file);
  file.addSeparator();
  file.add(quitm);
  quitm.addActionListener(e -> System.exit(1));
  return ret;
}
origin: stackoverflow.com

 @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.your_menu, menu);

  int positionOfMenuItem = 0; // or whatever...
  MenuItem item = menu.getItem(positionOfMenuItem);
  SpannableString s = new SpannableString("My red MenuItem");
  s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
  item.setTitle(s);
}
origin: stackoverflow.com

 @Override
public boolean onPrepareOptionsMenu(Menu menu) {
  super.onPrepareOptionsMenu(menu);
  menu.findItem(R.id.sort_by_name).setChecked(true);
  //Also you can do this for sub menu
  menu.getItem(firstItemIndex).getSubMenu().getItem(subItemIndex).setChecked(true);
  return true;
}
origin: stackoverflow.com

 @Override
public boolean onPrepareOptionsMenu(Menu menu) {
  menu.clear();
  if(isChangedStat) {
    menu.add(0, MENUITEM, 0, "True");
  } else {
    menu.add(0, MENUITEM, 0, "False");
  }
  return super.onPrepareOptionsMenu(menu);
}
origin: stackoverflow.com

 //anywhere in your code
...
mState = HIDE_MENU; // setting state
invalidateOptionsMenu(); // now onCreateOptionsMenu(...) is called again
...

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
  // inflate menu from xml
  MenuInflater inflater = getSupportMenuInflater();
  inflater.inflate(R.menu.settings, menu);

  if (mState == HIDE_MENU)
  {
    for (int i = 0; i < menu.size(); i++)
      menu.getItem(i).setVisible(false);
  }
}
origin: stackoverflow.com

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
  getSupportMenuInflater().inflate(R.menu.map_menu, menu);
  for (int i = 0; i < menu.size(); i++) {
    MenuItem item = menu.getItem(i);
    if (item.getItemId() == R.id.menu_more) {
      itemChooser = item.getActionView();
      if (itemChooser != null) {
        itemChooser.setOnClickListener(this);
      }
    }
  }
  return super.onCreateOptionsMenu(menu);
}
origin: stackoverflow.com

menu.clear();
if(enableAdd)
  menu.add(0, MENU_ADD, Menu.NONE, R.string.your-add-text).setIcon(R.drawable.your-add-icon);
if(enableList)
  menu.add(0, MENU_LIST, Menu.NONE, R.string.your-list-text).setIcon(R.drawable.your-list-icon);
if(enableRefresh)
  menu.add(0, MENU_REFRESH, Menu.NONE, R.string.your-refresh-text).setIcon(R.drawable.your-refresh-icon);
if(enableLogin)
  menu.add(0, MENU_LOGIN, Menu.NONE, R.string.your-login-text).setIcon(R.drawable.your-login-icon);
return super.onPrepareOptionsMenu(menu);
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case MENU_ADD: doAddStuff(); break;
case MENU_LIST: doListStuff(); break;
origin: stackoverflow.com

 @Override
public boolean onPrepareOptionsMenu(Menu menu) {

  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.addprojectmenu, menu);      

  menu.getItem(0).setEnabled(false); // here pass the index of save menu item
  return super.onPrepareOptionsMenu(menu);

}
origin: stackoverflow.com

 private MenuItem securedConnection;
private MenuItem insecuredConnection;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.connect_menu, menu);
  securedConnection = menu.getItem(0);
  insecuredConnection =  menu.getItem(1);
  return true;
}

public void foo(){
    securedConnection.setEnabled(true);
}
origin: stackoverflow.com

  for(int i = 0; i< menu.size(); i++)
    menu.getItem(i).setVisible(!mDrawerLayout.isDrawerOpen(mLeftDrawerView));
public boolean onOptionsItemSelected(MenuItem item) {
  switch(item.getItemId()) {
    case android.R.id.home:
      mDrawerToggle.onOptionsItemSelected(item);
origin: stackoverflow.com

 @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  Log.d(TAG, "onCreateOptionsMenu()");
  inflater.inflate(R.menu.your_menu, menu);
  for (int j = 0; j < menu.size(); j++) {
    MenuItem item = menu.getItem(j);
    Log.d(TAG, "set flag for " + item.getTitle());
    item.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
  }
}
origin: stackoverflow.com

 import android.support.v4.internal.view.SupportMenuItem;
import android.support.v7.internal.view.menu.MenuItemImpl;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import here.is.your.R;

public class EnhancedMenuInflater {

  public static void inflate(MenuInflater inflater, Menu menu, boolean forceVisible) {
    inflater.inflate(R.menu.menu, menu);

    if (!forceVisible) {
      return;
    }

    int size = menu.size();
    for (int i = 0; i < size; i++) {
      MenuItem item = menu.getItem(i);
      // check if app:showAsAction = "ifRoom"
      if (((MenuItemImpl) item).requestsActionButton()) {
        item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS);
      }
    }
  }
}
origin: stackoverflow.com

 public boolean onCreateOptionsMenu(Menu menu) { 
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu, menu);
  MenuItem someMenuItem = menu.getItem(R.id.menu_option_id);
  someMenuItem.setActionView(theView);
  return true;
}
origin: stackoverflow.com

  System.out.println("Unable to set LookAndFeel");
if(SystemTray.isSupported()){
  System.out.println("system tray supported");
  tray=SystemTray.getSystemTray();
  PopupMenu popup=new PopupMenu();
  MenuItem defaultItem=new MenuItem("Exit");
  defaultItem.addActionListener(exitListener);
  popup.add(defaultItem);
  defaultItem=new MenuItem("Open");
  defaultItem.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
  popup.add(defaultItem);
  trayIcon=new TrayIcon(image, "SystemTray Demo", popup);
  trayIcon.setImageAutoSize(true);
}else{
  System.out.println("system tray not supported");
    if(e.getNewState()==ICONIFIED){
      try {
        tray.add(trayIcon);
        setVisible(false);
        System.out.println("added to SystemTray");
origin: stackoverflow.com

if (SystemTray.isSupported()) {
  SystemTray tray = SystemTray.getSystemTray();
  PopupMenu popup = new PopupMenu();
  MenuItem showItem = new MenuItem("Show");
  showItem.addActionListener(showListener);
  popup.add(showItem);
  MenuItem closeItem = new MenuItem("Close");
  closeItem.addActionListener(closeListener);
  popup.add(closeItem);
  trayIcon = new TrayIcon(image, "Title", popup);
  trayIcon.addActionListener(showListener);
    tray.add(trayIcon);
  } catch (AWTException e) {
    System.err.println(e);
  trayIcon.displayMessage("Some message.",
      "Some other message.",
      TrayIcon.MessageType.INFO);
origin: stackoverflow.com

@Override
public void start(Stage stage) {
  Menu fileMenu = new Menu("_File");
  MenuItem newFileMenuItem = new MenuItem("_New...");
  newFileMenuItem.setAccelerator(
    KeyCombination.keyCombination("SHORTCUT+N")
  );
  newFileMenuItem.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
  fileMenu.getItems().add(
      newFileMenuItem
  );
  MenuBar menuBar = new MenuBar();
  menuBar.getMenus().setAll(
      fileMenu
  );
  layout.setPrefSize(200, 100);
  stage.setScene(new Scene(layout));
  stage.show();
origin: stackoverflow.com

  return;
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon =
    new TrayIcon(createImage("images/bulb.gif", "tray icon"));
MenuItem aboutItem = new MenuItem("About");
CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
Menu displayMenu = new Menu("Display");
MenuItem errorItem = new MenuItem("Error");
MenuItem warningItem = new MenuItem("Warning");
MenuItem infoItem = new MenuItem("Info");
MenuItem noneItem = new MenuItem("None");
popup.add(aboutItem);
popup.addSeparator();
popup.add(cb1);
popup.add(cb2);
popup.addSeparator();
popup.add(displayMenu);
displayMenu.add(errorItem);
displayMenu.add(warningItem);
displayMenu.add(infoItem);
displayMenu.add(noneItem);
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
origin: stackoverflow.com

if (SystemTray.isSupported() == false) {
  System.err.println("No system tray available");
  return;
tray = SystemTray.getSystemTray();
PropertyChangeListener propListener = new PropertyChangeListener() {
tray.addPropertyChangeListener("trayIcons", propListener);
icon = new BevelArrowIcon(BevelArrowIcon.UP, false, false);
image = iconToImage(icon);
icon1 = new BevelArrowIcon(BevelArrowIcon.DOWN, false, false);
image1 = iconToImage(icon1);
PopupMenu popup = new PopupMenu();
MenuItem item = new MenuItem("Hello, World");
trayIcon = new TrayIcon(image, "Tip Text", popup);
ActionListener menuActionListener = new ActionListener() {
    trayIcon.displayMessage("Good-bye", "Cruel World",
        TrayIcon.MessageType.WARNING);
item.addActionListener(menuActionListener);
popup.add(item);
ActionListener actionListener = new ActionListener() {
trayIcon.addActionListener(actionListener);
try {
  tray.add(trayIcon);
origin: stackoverflow.com

MenuItem item = menu.add("Search");
item.setIcon(android.R.drawable.ic_menu_search);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
SearchView sv = new SearchView(getActivity());
sv.setOnQueryTextListener(this);
item.setActionView(sv);
java.awtMenu

Most used methods

  • add
  • <init>
  • addSeparator
  • getItem
  • getItemCount
  • getLabel
  • insert
  • remove
  • addActionListener
  • setLabel
  • getName
  • getParent
  • getName,
  • getParent,
  • removeAll,
  • setName,
  • FileMenu,
  • ViewMenu,
  • addListener,
  • addMenuItem,
  • addMenuListener,
  • addNotify

Popular in Java

  • Finding current android device location
  • setScale (BigDecimal)
  • setRequestProperty (URLConnection)
  • addToBackStack (FragmentTransaction)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • JPanel (javax.swing)
  • Join (org.hibernate.mapping)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now