本文整理汇总了Java中javax.swing.JMenuItem.isSelected方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.isSelected方法的具体用法?Java JMenuItem.isSelected怎么用?Java JMenuItem.isSelected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.isSelected方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
* Paints a menu item
* @param g The graphics to use
* @param menuItem The menu item to paint
* @param hasCursor Whether or not the cursor is over the component
* @param defaultTextIconGap The gap between the text and the icon
*/
private static final void paintMenuItem(Graphics2D g, JMenuItem menuItem, boolean hasCursor, int defaultTextIconGap){
g.setColor(Main.config.customColors ? Main.config.background : Color.BLACK);
g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
if(menuItem instanceof JCheckBoxMenuItem && menuItem.isSelected()){
g.drawImage(ColorManager.checkmark, 0, 0, 22, 22, 0, 0, 100, 100, menuItem);
}else if(menuItem instanceof JMenu){
g.drawImage(ColorManager.arrow, menuItem.getWidth() - 12, 5, menuItem.getWidth(), 17, 0, 0, 128, 128, menuItem);
}
g.setColor(Main.config.customColors ? Main.config.foreground : Color.CYAN);
if(hasCursor){
g.drawLine(0, 0, menuItem.getWidth(), 0);
g.drawLine(0, menuItem.getHeight() - 1, menuItem.getWidth(), menuItem.getHeight() - 1);
Composite prev = g.getComposite();
g.setComposite(MenuItemUI.mode);
g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
g.setComposite(prev);
}
FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
int mnemIndex = menuItem.getDisplayedMnemonicIndex();
int y = (22 - fm.getHeight()) / 2;
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, menuItem.getText(), mnemIndex, 22 + defaultTextIconGap, y + fm.getAscent());
}
示例2: NbMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
* @param it
* @return instance of NbMenuItem constructed from parameter it */
public NbMenuItem(JMenuItem it) {
setName(it.getText());//getLabel();
this.accelerator = (it.getAccelerator() == null) ? null : it.getAccelerator().toString();
this.mnemo = (char) it.getMnemonic();
// System.out.println("NbMenuItem ["+name+"] - mnemo: ["+it.getMnemonic()+"]"); why are the mnemonic always in capital?
this.enabled = it.isEnabled();
this.checkbox = it instanceof JCheckBoxMenuItem;
this.radiobutton = it instanceof JRadioButtonMenuItem;
this.checked = it.isSelected();
}
示例3: getValue
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
* Returns the current value of a given options name. If the option is a
* checkbox menu, the value is <code>0</code> for <code>false</code> and
* <code>1</code> for <code>true</code>.
* @param name the name of the checkbox menu item for which to get the value
* @return the current value of the checkbox item with the given name
*/
public int getValue(String name) {
JMenuItem item = this.itemMap.get(name);
if (item instanceof BehaviourOption) {
return ((BehaviourOption) item).getValue();
} else {
return item.isSelected() ? 1 : 0;
}
}