本文整理汇总了Java中javax.swing.JMenuItem.getModel方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.getModel方法的具体用法?Java JMenuItem.getModel怎么用?Java JMenuItem.getModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.getModel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintIcon
import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
JMenuItem b = (JMenuItem) c;
ButtonModel model = b.getModel();
g.translate(x, y);
boolean isSelected = model.isSelected();
boolean isEnabled = model.isEnabled();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// draw check mark
if (isSelected) {
g2.setStroke(CHECKBOX_STROKE);
if (isEnabled) {
g2.setColor(Colors.CHECKBOX_CHECKED);
} else {
g2.setColor(Colors.CHECKBOX_CHECKED_DISABLED);
}
g2.drawLine(2, 6, 5, 8);
g2.drawLine(5, 8, 9, 1);
}
g.translate(-x, -y);
}
示例2: paintBackground
import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
if (model.isArmed()
|| (menuItem instanceof JMenu && model.isSelected())) {
paintButtonPressed(g, menuItem);
} else {
g.setColor(this.colorBg);
//g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());//(0, 0, gap + 1, menuItem.getHeight());
// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
// if (menuItem.getIcon() != null) {
// int gap = menuItem.getIcon().getIconWidth() + 2;
// g.setColor(this.darkColor);
// g.drawLine(gap, 0, gap, menuItem.getHeight());
// g.setColor(this.lightColor);
// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
// }
}
g.setColor(oldColor);
}
示例3: performAction
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static void performAction(StayOpen item, int modifiers) {
JMenuItem i = item.getItem();
// Skip disabled items
if (!item.getItem().isEnabled()) return;
// Handle toggle items
if (i.getModel() instanceof JToggleButton.ToggleButtonModel)
i.setSelected(!i.isSelected());
// Invoke item action
item.actionPerformed(new ActionEvent(item, ActionEvent.ACTION_PERFORMED,
item.getItem().getActionCommand(),
EventQueue.getMostRecentEventTime(), modifiers));
}
示例4: drawMenuItemBackground
import javax.swing.JMenuItem; //导入方法依赖的package包/类
public static void drawMenuItemBackground(Graphics g, JMenuItem menuItem) {
Color oldColor = g.getColor();
ButtonModel model = menuItem.getModel();
int w = menuItem.getWidth();
int h = menuItem.getHeight();
if (model.isArmed() || model.isSelected() && menuItem instanceof JMenu) {
g.setColor(Colors.MENU_ITEM_BACKGROUND_SELECTED);
g.fillRect(0, 0, w, h);
} else if (!(menuItem instanceof JMenu && ((JMenu) menuItem).isTopLevelMenu())) {
drawMenuItemFading(menuItem, g);
}
g.setColor(oldColor);
}
示例5: paintBackground
import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
int menuWidth = menuItem.getWidth();
int menuHeight = menuItem.getHeight();
g.setColor(colorBg);
g.fillRect(0, 0, menuWidth, menuHeight);
if (model.isArmed()
|| (menuItem instanceof JMenu && model.isSelected())) {
paintButtonPressed(g, menuItem);
} else {
// if (menuItem.getIcon() != null) {
// int gap = menuItem.getIcon().getIconWidth() + 2;
// g.setColor(this.darkColor);
// g.drawLine(gap, 0, gap, menuItem.getHeight());
// g.setColor(this.lightColor);
// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
// }
}
if (menuItem instanceof JCheckBoxMenuItem) {
if (((JCheckBoxMenuItem) menuItem).isSelected()) {
// chkIcon.paintIcon(menuItem, g, 5, 5);
}
}
g.setColor(oldColor);
}
示例6: paintIcon
import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
JMenuItem b = (JMenuItem) c;
ButtonModel bm = b.getModel();
g.translate(x, y);
boolean isSelected = bm.isSelected();
boolean isEnabled = bm.isEnabled();
boolean isPressed = bm.isPressed();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// drawing background section
if (!isEnabled) {
g2.setColor(Colors.RADIOBUTTON_BORDER_DISABLED);
} else {
if (isPressed) {
g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
} else {
g2.setColor(Colors.RADIOBUTTON_BORDER);
}
}
g2.setStroke(RADIO_STROKE);
Shape circle = new Ellipse2D.Double(0, 0, 9, 9);
g2.draw(circle);
// drawing sphere
if (isSelected) {
if (isEnabled) {
g2.setColor(Colors.RADIOBUTTON_CHECKED);
} else {
g2.setColor(Colors.RADIOBUTTON_CHECKED_DISABLED);
}
circle = new Ellipse2D.Double(3, 3, 4, 4);
g2.fill(circle);
}
g.translate(-x, -y);
}