java.awt.Menu类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中java.awt.Menu类的一些代码示例,展示了Menu类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Menu类的具体详情如下:
包路径:java.awt.Menu
类名称:Menu

暂无

代码示例

代码示例来源: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);

相关文章