本文整理了Java中java.awt.MenuItem.getLabel()
方法的一些代码示例,展示了MenuItem.getLabel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.getLabel()
方法的具体详情如下:
包路径:java.awt.MenuItem
类名称:MenuItem
方法名:getLabel
暂无
代码示例来源:origin: i2p/i2p.i2p
if (awt != null) {
MenuItem item = awt.getItem(0);
String oldStatus = item.getLabel();
if (!status.equals(oldStatus))
item.setLabel(status);
代码示例来源:origin: abbot/abbot
/** Provide a string representation of the given component (Component or
* MenuComponent.
*/
public static String toString(Object obj) {
if (obj instanceof Component)
return toString((Component)obj);
else if (obj instanceof MenuBar)
return "MenuBar";
else if (obj instanceof MenuItem)
return ((MenuItem)obj).getLabel();
return obj.toString();
}
代码示例来源:origin: net.imagej/ij
/** Called once when ImageJ quits. */
public static void savePreferences(Properties prefs) {
int index = 0;
for (Enumeration en=pluginsPrefs.elements(); en.hasMoreElements();) {
String key = "plugin" + (index/10)%10 + index%10;
String value = (String)en.nextElement();
prefs.put(key, value);
index++;
}
int n = openRecentMenu.getItemCount();
for (int i=0; i<n; i++) {
String key = ""+i;
if (key.length()==1) key = "0"+key;
key = "recent"+key;
prefs.put(key, openRecentMenu.getItem(i).getLabel());
}
prefs.put(Prefs.MENU_SIZE, Integer.toString(fontSize));
}
代码示例来源:origin: imagej/ImageJA
/** Called once when ImageJ quits. */
public static void savePreferences(Properties prefs) {
int index = 0;
for (Enumeration en=pluginsPrefs.elements(); en.hasMoreElements();) {
String key = "plugin" + (index/10)%10 + index%10;
String value = (String)en.nextElement();
prefs.put(key, value);
index++;
}
int n = openRecentMenu.getItemCount();
for (int i=0; i<n; i++) {
String key = ""+i;
if (key.length()==1) key = "0"+key;
key = "recent"+key;
prefs.put(key, openRecentMenu.getItem(i).getLabel());
}
prefs.put(Prefs.MENU_SIZE, Integer.toString(fontSize));
}
代码示例来源:origin: net.imagej/ij
/** Inserts 'item' into 'menu' in alphanumeric order. */
static void addOrdered(Menu menu, MenuItem item) {
String label = item.getLabel();
int start = addPluginSeparatorIfNeeded(menu);
for (int i=start; i<menu.getItemCount(); i++) {
if (label.compareTo(menu.getItem(i).getLabel())<0) {
menu.insert(item, i);
return;
}
}
menu.add(item);
}
代码示例来源:origin: imagej/ImageJA
/** Inserts 'item' into 'menu' in alphanumeric order. */
static void addOrdered(Menu menu, MenuItem item) {
String label = item.getLabel();
int start = addPluginSeparatorIfNeeded(menu);
for (int i=start; i<menu.getItemCount(); i++) {
if (label.compareTo(menu.getItem(i).getLabel())<0) {
menu.insert(item, i);
return;
}
}
menu.add(item);
}
代码示例来源:origin: net.imagej/ij
static void addItemSorted(Menu menu, MenuItem item, int startingIndex) {
String itemLabel = item.getLabel();
int count = menu.getItemCount();
boolean inserted = false;
for (int i=startingIndex; i<count; i++) {
MenuItem mi = menu.getItem(i);
String label = mi.getLabel();
//IJ.log(i+ " "+itemLabel+" "+label + " "+(itemLabel.compareTo(label)));
if (itemLabel.compareTo(label)<0) {
menu.insert(item, i);
inserted = true;
break;
}
}
if (!inserted) menu.add(item);
}
代码示例来源:origin: imagej/ImageJA
static void addItemSorted(Menu menu, MenuItem item, int startingIndex) {
String itemLabel = item.getLabel();
int count = menu.getItemCount();
boolean inserted = false;
for (int i=startingIndex; i<count; i++) {
MenuItem mi = menu.getItem(i);
String label = mi.getLabel();
//IJ.log(i+ " "+itemLabel+" "+label + " "+(itemLabel.compareTo(label)));
if (itemLabel.compareTo(label)<0) {
menu.insert(item, i);
inserted = true;
break;
}
}
if (!inserted) menu.add(item);
}
代码示例来源:origin: gurkenlabs/litiengine
public static void loadRecentFiles() {
recentFiles.removeAll();
for (String recent : userPreferences.getLastOpenedFiles()) {
if (recent != null && !recent.isEmpty() && new File(recent).exists()) {
MenuItem fileButton = new MenuItem(recent);
fileButton.addActionListener(a -> {
log.log(Level.INFO, "load " + fileButton.getLabel());
EditorScreen.instance().load(new File(fileButton.getLabel()));
});
recentFiles.add(fileButton);
}
}
}
代码示例来源:origin: net.imagej/ij
/** Returns, as an array of strings, a list of the LUTs in the Image/Lookup Tables menu. */
public static String[] getLuts() {
ArrayList list = new ArrayList();
Hashtable commands = Menus.getCommands();
Menu lutsMenu = Menus.getImageJMenu("Image>Lookup Tables");
if (commands==null || lutsMenu==null)
return new String[0];
for (int i=0; i<lutsMenu.getItemCount(); i++) {
MenuItem menuItem = lutsMenu.getItem(i);
if (menuItem.getActionListeners().length == 0) // separator?
continue;
String label = menuItem.getLabel();
if (label.equals("Invert LUT") || label.equals("Apply LUT"))
continue;
String command = (String)commands.get(label);
if (command==null || command.startsWith("ij.plugin.LutLoader"))
list.add(label);
}
return (String[])list.toArray(new String[list.size()]);
}
代码示例来源:origin: net.imagej/ij
public static String[] getSampleImageNames() {
ArrayList list = new ArrayList();
Hashtable commands = Menus.getCommands();
Menu samplesMenu = Menus.getImageJMenu("File>Open Samples");
if (samplesMenu==null)
return new String[0];
for (int i=0; i<samplesMenu.getItemCount(); i++) {
MenuItem menuItem = samplesMenu.getItem(i);
if (menuItem.getActionListeners().length == 0) continue; // separator?
String label = menuItem.getLabel();
if (label.contains("Cache Sample Images")) continue;
String command = (String)commands.get(label);
if (command==null) continue;
String[] items = command.split("\"");
if (items.length!=3) continue;
String name = items[1];
list.add(name);
}
return (String[])list.toArray(new String[list.size()]);
}
代码示例来源:origin: net.imagej/imagej-legacy
/**
* Helper method to look up special cases for menu weighting
*/
private int getIndex(final Menu menu, final String label) {
// Place export sub-menu after import sub-menu
if (menu.getLabel().equals("File") && label.equals("Export")) {
for (int i = 0; i < menu.getItemCount(); i++) {
final MenuItem menuItem = menu.getItem(i);
if (menuItem.getLabel().equals("Import")) return i + 1;
}
}
// TODO pass and use actual command weight from IJ2.. maybe?
// No special case: append to end of menu
return menu.getItemCount();
}
代码示例来源:origin: net.imagej/ij
/** Opens a file from the File/Open Recent menu
and returns 'true' if successful. */
boolean openRecent(String cmd) {
Menu menu = Menus.getOpenRecentMenu();
if (menu==null) return false;
for (int i=0; i<menu.getItemCount(); i++) {
if (menu.getItem(i).getLabel().equals(cmd)) {
IJ.open(cmd);
return true;
}
}
return false;
}
代码示例来源:origin: imagej/ImageJA
/** Opens a file from the File/Open Recent menu
and returns 'true' if successful. */
boolean openRecent(String cmd) {
Menu menu = Menus.getOpenRecentMenu();
if (menu==null) return false;
for (int i=0; i<menu.getItemCount(); i++) {
if (menu.getItem(i).getLabel().equals(cmd)) {
IJ.open(cmd);
return true;
}
}
return false;
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Loads the {@link LyrebirdTrayIcon} in the current OS's system tray.
*/
private void loadTrayIcon() {
LOG.debug("Registering tray icon for Lyrebird...");
LOG.debug("Creating a tray icon...");
final SystemTray tray = SystemTray.get();
tray.setImage(lyrebirdTrayIcon.getIcon());
tray.setTooltip("Lyrebird");
LOG.debug("Adding items to tray icon's menu...");
final Menu menu = tray.getMenu();
lyrebirdTrayIcon.getMenuItems().forEach((item, action) -> {
LOG.debug("Adding menu item : {} (callback : {})", item, action);
final MenuItem menuItem = new MenuItem(item.getLabel());
menuItem.setCallback(action);
menu.add(menuItem);
});
LOG.debug("Finished creating tray icon!");
}
代码示例来源:origin: net.java.openjdk.cacio/cacio-shared
@Override
void postInitSwingComponent() {
setLabel(getAWTMenu().getLabel());
setEnabled(getAWTMenu().isEnabled());
if (needActionProxy()) {
getSwingMenu().addActionListener(new ProxyListener());
}
}
代码示例来源:origin: net.imagej/ij
/** Adds a file path to the beginning of the File/Open Recent submenu. */
public static synchronized void addOpenRecentItem(String path) {
if (ij==null) return;
int count = openRecentMenu.getItemCount();
for (int i=0; i<count; ) {
if (openRecentMenu.getItem(i).getLabel().equals(path)) {
openRecentMenu.remove(i);
count--;
} else
i++;
}
if (count==MAX_OPEN_RECENT_ITEMS)
openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1);
MenuItem item = new MenuItem(path);
openRecentMenu.insert(item, 0);
item.addActionListener(ij);
}
代码示例来源:origin: imagej/ImageJA
/** Adds a file path to the beginning of the File/Open Recent submenu. */
public static synchronized void addOpenRecentItem(String path) {
if (ij==null) return;
int count = openRecentMenu.getItemCount();
for (int i=0; i<count; ) {
if (openRecentMenu.getItem(i).getLabel().equals(path)) {
openRecentMenu.remove(i);
count--;
} else
i++;
}
if (count==MAX_OPEN_RECENT_ITEMS)
openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1);
MenuItem item = new MenuItem(path);
openRecentMenu.insert(item, 0);
item.addActionListener(ij);
}
代码示例来源:origin: net.imagej/ij
/** Open the file and move the path to top of the submenu. */
public void run() {
Opener o = new Opener();
o.open(path);
Menu menu = Menus.getOpenRecentMenu();
int n = menu.getItemCount();
int index = 0;
for (int i=0; i<n; i++) {
if (menu.getItem(i).getLabel().equals(path)) {
index = i;
break;
}
}
if (index>0) {
MenuItem item = menu.getItem(index);
menu.remove(index);
menu.insert(item, 0);
}
}
代码示例来源:origin: imagej/ImageJA
/** Open the file and move the path to top of the submenu. */
public void run() {
Opener o = new Opener();
o.open(path);
Menu menu = Menus.getOpenRecentMenu();
int n = menu.getItemCount();
int index = 0;
for (int i=0; i<n; i++) {
if (menu.getItem(i).getLabel().equals(path)) {
index = i;
break;
}
}
if (index>0) {
MenuItem item = menu.getItem(index);
menu.remove(index);
menu.insert(item, 0);
}
}
内容来源于网络,如有侵权,请联系作者删除!