本文整理汇总了Java中javax.swing.ButtonModel.isSelected方法的典型用法代码示例。如果您正苦于以下问题:Java ButtonModel.isSelected方法的具体用法?Java ButtonModel.isSelected怎么用?Java ButtonModel.isSelected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.ButtonModel
的用法示例。
在下文中一共展示了ButtonModel.isSelected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintIcon
import javax.swing.ButtonModel; //导入方法依赖的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.ButtonModel; //导入方法依赖的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: paintIcon
import javax.swing.ButtonModel; //导入方法依赖的package包/类
public void paintIcon(Graphics2D g,ButtonInfo info) {
AbstractButton button = info.button;
Icon icon = button.getIcon();
ButtonModel model = button.getModel();
if(model.isRollover() && button.getRolloverIcon()!=null)
icon = button.getRolloverIcon();
if(model.isPressed() && button.getPressedIcon()!=null)
icon = button.getPressedIcon();
if(model.isSelected() && button.getSelectedIcon()!=null)
icon = button.getSelectedIcon();
if(model.isRollover() && model.isSelected() && button.getRolloverSelectedIcon()!=null)
icon = button.getRolloverSelectedIcon();
if(isEnabled(button)==false && button.getDisabledIcon()!=null)
icon = button.getDisabledIcon();
if(isEnabled(button)==false && model.isSelected() && button.getDisabledIcon()!=null)
icon = button.getDisabledSelectedIcon();
if(icon!=null) {
g.setComposite(isEnabled(button) ? AlphaComposite.SrcOver : SRC_OVER_TRANSLUCENT);
icon.paintIcon(button, g, info.iconRect.x, info.iconRect.y);
}
}
示例4: paintBackground
import javax.swing.ButtonModel; //导入方法依赖的package包/类
@Override
public void paintBackground(Graphics2D g,ButtonInfo info) {
super.paintBackground(g, info);
if(info.button.isContentAreaFilled() || info.button.isBorderPainted()) {
ButtonModel model = info.button.getModel();
if(model.isSelected() || model.isArmed() || isSpacebarPressed(info.button)) {
g = (Graphics2D)g.create();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.clip( info.fill);
g.setColor(new Color(0,0,0,15));
g.setStroke(outline1);
g.draw( info.fill );
g.setStroke(outline2);
g.draw( info.fill );
g.setStroke(outline3);
g.draw( info.fill );
}
}
}
示例5: getPreImg
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* <pre>
* 根据按钮状态, 获取当前状态下图片信息。
*
* According to the button state, access to the current
* state of the picture information.
* </pre>
*
* @param c <code>CheckBoxMenuItem</code> object.
* @param model <code>ButtonModel</code>
* @return <code>Image</code> when is selected return current image, otherwise return null.
*/
public Image getPreImg(Component c, ButtonModel model)
{
if (!model.isSelected())
{
return null;
}
if (model.isArmed())
{
return getRollverImg();
}
else
{
return getNormalImg();
}
}
示例6: getPreImg
import javax.swing.ButtonModel; //导入方法依赖的package包/类
public Image getPreImg(Component c, ButtonModel model)
{
JMenu menu = (JMenu) c;
if (menu.getItemCount() > 0)
{
if (model.isSelected())
{
return getRollverImg();
}
else
{
return getNormalImg();
}
}
return null;
}
示例7: paintBackground
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* Paints background of the menu item
*
* @param g
* The graphics context used to paint this menu item
* @param menuItem
* menu item to paint
* @param bgColor
* Background color to use when painting menu item
*/
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
{
// Menu item is considered to be highlighted when it is selected.
// But we don't want to paint the background of JCheckBoxMenuItems
ButtonModel mod = menuItem.getModel();
Color saved = g.getColor();
if (mod.isArmed() || ((menuItem instanceof JMenu) && mod.isSelected()))
{
g.setColor(bgColor);
g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
}
else if (menuItem.isOpaque())
{
g.setColor(menuItem.getBackground());
g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
}
g.setColor(saved);
}
示例8: paintBackground
import javax.swing.ButtonModel; //导入方法依赖的package包/类
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(this.colorBg);
g.fillRect(0, 0, menuWidth, menuHeight);
if(model.isArmed() || menuItem instanceof JMenu && model.isSelected()) {
this.paintButtonPressed(g, menuItem);
}
if(menuItem instanceof JCheckBoxMenuItem) {
((JCheckBoxMenuItem)menuItem).isSelected();
}
g.setColor(oldColor);
}
示例9: getIcon
import javax.swing.ButtonModel; //导入方法依赖的package包/类
private Icon getIcon(JMenuItem aMenuItem, Icon defaultIcon)
/* 63: */ {
/* 64:114 */ Icon icon = aMenuItem.getIcon();
/* 65:115 */ if (icon == null) {
/* 66:116 */ return defaultIcon;
/* 67: */ }
/* 68:118 */ ButtonModel model = aMenuItem.getModel();
/* 69:119 */ if (!model.isEnabled()) {
/* 70:120 */ return model.isSelected() ? aMenuItem.getDisabledSelectedIcon() : aMenuItem.getDisabledIcon();
/* 71: */ }
/* 72:123 */ if ((model.isPressed()) && (model.isArmed()))
/* 73: */ {
/* 74:124 */ Icon pressedIcon = aMenuItem.getPressedIcon();
/* 75:125 */ return pressedIcon != null ? pressedIcon : icon;
/* 76: */ }
/* 77:126 */ if (model.isSelected())
/* 78: */ {
/* 79:127 */ Icon selectedIcon = aMenuItem.getSelectedIcon();
/* 80:128 */ return selectedIcon != null ? selectedIcon : icon;
/* 81: */ }
/* 82:130 */ return icon;
/* 83: */ }
示例10: ensureSubMenuInstalled
import javax.swing.ButtonModel; //导入方法依赖的package包/类
private void ensureSubMenuInstalled()
/* 92: */ {
/* 93:156 */ if (this.propertyPrefix.equals("MenuItem")) {
/* 94:157 */ return;
/* 95: */ }
/* 96:159 */ ButtonModel model = this.menuItem.getModel();
/* 97: */
/* 98: */
/* 99: */
/* 100:163 */ boolean oldArmed = model.isArmed();
/* 101:164 */ boolean oldSelected = model.isSelected();
/* 102: */
/* 103:166 */ uninstallRolloverListener();
/* 104:167 */ uninstallDefaults();
/* 105:168 */ this.propertyPrefix = "MenuItem";
/* 106:169 */ installDefaults();
/* 107: */
/* 108: */
/* 109:172 */ model.setArmed(oldArmed);
/* 110:173 */ model.setSelected(oldSelected);
/* 111: */ }
示例11: setSelected
import javax.swing.ButtonModel; //导入方法依赖的package包/类
public void setSelected(ButtonModel m, boolean b) {
if (b == false) {
for (ButtonModel model : selected) {
if (model.isSelected() && model != m) {
selected.remove(m);
return;
}
}
} else {
selected.add(m);
}
}
示例12: store
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/** Stores all models created in the StoreGroup into given
* EditableProperties.
* @param editableProperties The properties where to store the
* values.
*/
public void store( EditableProperties editableProperties ) {
for (Map.Entry<String,Object[]> entry : models.entrySet()) {
String key = entry.getKey();
Object[] params = entry.getValue();
if ( params[0] instanceof ButtonModel ) {
ButtonModel model = (ButtonModel)params[0];
boolean value = model.isSelected();
if ( params[2] == Boolean.TRUE ) {
value = !value;
}
editableProperties.setProperty( key, encodeBoolean( value, (Integer)params[1] ) );
}
else if ( params[0] instanceof Document && modifiedDocuments.contains(params[0])) {
Document doc = (Document)params[0];
String txt;
try {
txt = doc.getText(0, doc.getLength());
} catch (BadLocationException e) {
txt = ""; // NOI18N
}
editableProperties.setProperty( key, txt );
}
}
}
示例13: drawMenuItemBackground
import javax.swing.ButtonModel; //导入方法依赖的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);
}
示例14: paintBackground
import javax.swing.ButtonModel; //导入方法依赖的package包/类
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
JMenu menu = (JMenu) menuItem;
ButtonModel buttonmodel = menu.getModel();
int w = menu.getWidth();
int h = menu.getHeight();
Color oldColor = g.getColor();
if (!menu.isContentAreaFilled() || !menu.isOpaque()) {
// do nothing
} else {
if (menu.isTopLevelMenu()) {
if (buttonmodel.isSelected()) {
CachedPainter.drawMenuBackground(menuItem, g, 0, 0, w, h);
} else if (buttonmodel.isRollover() && buttonmodel.isEnabled()) {
g.setColor(Colors.MENUBAR_BACKGROUND_HIGHLIGHT);
g.fillRect(0, 0, w, h);
g.setColor(Colors.MENU_ITEM_BACKGROUND);
g.drawRect(0, 0, w - 1, h - 1);
} else {
if (menuItem.getParent() instanceof JMenuBar) {
((MenuBarUI) ((JMenuBar) menuItem.getParent()).getUI()).update(g, menuItem);
}
}
} else {
if (!menuItem.getModel().isSelected()) {
RapidLookTools.drawMenuItemFading(menuItem, g);
} else {
RapidLookTools.drawMenuItemBackground(g, menuItem);
}
}
}
g.setColor(oldColor);
}
示例15: paintComponent
import javax.swing.ButtonModel; //导入方法依赖的package包/类
protected void paintComponent(Graphics graphics) {
SwingTools.disableClearType(this);
((Graphics2D)graphics).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Graphics2D g = (Graphics2D)graphics.create();
ButtonModel model = this.getModel();
if(model.isEnabled() && (model.isRollover() || model.isSelected())) {
g.setColor(this.colorHover);
g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10);
}
g.dispose();
super.paintComponent(graphics);
}