javax.swing
Interface ButtonModel
- ItemSelectable
- DefaultButtonModel, JToggleButton.ToggleButtonModel
State Model for buttons.
This model is used for check boxes and radio buttons, which are
special kinds of buttons, as well as for normal buttons.
For check boxes and radio buttons, pressing the mouse selects
the button. For normal buttons, pressing the mouse "arms" the
button. Releasing the mouse over the button then initiates a
button press, firing its action event. Releasing the
mouse elsewhere disarms the button.
In use, a UI will invoke
setSelected(boolean) when a mouse
click occurs over a check box or radio button. It will invoke
setArmed(boolean) when the mouse is pressed over a regular
button and invoke
setPressed(boolean) when the mouse is released.
If the mouse travels outside the button in the meantime,
setArmed(false) will tell the button not to fire
when it sees
setPressed. (If the mouse travels
back in, the button will be rearmed.)
Note:
A button is triggered when it is both "armed" and "pressed".
View More Examples of addActionListener(ActionListener l)
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void addActionListener(ActionListener l) {
13: inner.addActionListener(l);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void addActionListener(ActionListener l) {
11: other.addActionListener(l);
View Full Code Here
View More Examples of addChangeListener(ChangeListener l)
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void addChangeListener(ChangeListener l) {
13: inner.addChangeListener(l);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void addChangeListener(ChangeListener l) {
11: other.addChangeListener(l);
View Full Code Here
View More Examples of addItemListener(ItemListener l)
1:
2: public void setModel(ButtonModel buttonmodel) throws IllegalArgumentException {
3: ...
4: if (buttonmodel == null)
5: throw new IllegalArgumentException("null model");
6: ...
7: super.setModel(buttonmodel);
8: buttonmodel.addItemListener(this);
9: }
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void addItemListener(ItemListener l) {
13: inner.addItemListener(l);
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: itemlistener.handle = checkbox;
6: checkbox.addItemListener(itemlistener);
7: }
8: ...
9: itemlistener.handle = checkboxmenuitem;
10: checkboxmenuitem.addItemListener(itemlistener);
11: }
12: ...
13: itemlistener.handle = choice;
14: choice.addItemListener(itemlistener);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void addItemListener(ItemListener l) {
11: other.addItemListener(l);
View Full Code Here
getActionCommand
public String getActionCommand()
Returns the action command for this button.
- the String that identifies the generated event
View More Examples of getActionCommand()
1: {
2: ButtonModel selection = this.getSelection();
3: if (selection==null) return null;
4: ...
5:
6: String selected = selection.getActionCommand();
7: if (selected==null) return null;
8: ...
9: AbstractButton button = (AbstractButton)buttons.nextElement();
10: boolean selected = (value==null) || button.getActionCommand().equals(svalue);
11: this.setSelected(button.getModel(), selected);
12: ...
13: AbstractButton button = (AbstractButton)buttons.nextElement();
14: boolean selected = (value!=null) && button.getActionCommand().equals(svalue);
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public String getActionCommand() {
13: return inner.getActionCommand();
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public String getActionCommand() {
11: return other.getActionCommand();
View Full Code Here
getMnemonic
public int getMnemonic()
Gets the keyboard mnemonic for this model
- an int specifying the accelerator key
View More Examples of getMnemonic()
1: AbstractButton ab = (AbstractButton)c;
2: ButtonModel bm = ab.getModel();
3: Dimension size = c.getSize();
4: ...
5: FontMetrics fm = g.getFontMetrics();
6: ButtonModel bm = ab.getModel();
7:
8: ...
9: BasicGraphicsUtils.drawString( g, text,
10: bm.getMnemonic(),
11: textRect.x, textRect.y + fm.getAscent());
12: ...
13: BasicGraphicsUtils.drawString( g, text,
14: bm.getMnemonic(),
View Full Code Here
1: AbstractButton ab = (AbstractButton)c;
2: ButtonModel bm = ab.getModel();
3: Dimension size = c.getSize();
4: ...
5: FontMetrics fm = g.getFontMetrics();
6: ButtonModel bm = ab.getModel();
7:
8: ...
9: BasicGraphicsUtils.drawString( g, text,
10: bm.getMnemonic(),
11: textRect.x,
12: ...
13: BasicGraphicsUtils.drawString( g, text,
14: bm.getMnemonic(),
View Full Code Here
1: AbstractButton ab = (AbstractButton)c;
2: ButtonModel bm = ab.getModel();
3: Dimension size = ab.getSize();
4: ...
5: FontMetrics fm = g.getFontMetrics();
6: ButtonModel bm = ab.getModel();
7:
8: ...
9: BasicGraphicsUtils.drawString( g, text,
10: bm.getMnemonic(),
11: textRect.x + shiftOffset,
12: ...
13: BasicGraphicsUtils.drawString( g, text,
14: bm.getMnemonic(),
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: AbstractButton b = (AbstractButton) c;
6: ButtonModel model = b.getModel();
7:
8: ...
9: g.setColor(b.getForeground());
10: BasicGraphicsUtils.drawString(g, text, model.getMnemonic(),
11: textRect.x, textRect.y + fm.getAscent());
12: ...
13: g.setColor(UIManager.getColor("Label.disabledForeground"));
14: BasicGraphicsUtils.drawString(g, text, model.getMnemonic(),
View Full Code Here
isArmed
public boolean isArmed()
Indicates partial commitment towards pressing the
button.
- true if the button is armed, and ready to be pressed
View More Examples of isArmed()
1: import ;
2: import ;
3: import ;
4: ...
5: inner.setSize(getWidth(), getHeight());
6: ButtonModel model = getModel();
7: ...
8: inner.setForeground(model.isArmed() ? UIManager
9: .getColor("MenuItem.selectionForeground") : getForeground());
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public boolean isArmed() {
11: return other.isArmed();
View Full Code Here
isEnabled
public boolean isEnabled()
Indicates if the button can be selected or pressed by
an input device (such as a mouse pointer). (Check boxes
are selected, regular buttons are "pressed".)
- true if the button is enabled, and therefore
selectable (or pressable)
View More Examples of isEnabled()
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public boolean isEnabled() {
13: return inner.isEnabled() && MySwingUtils.isHierarchyEnabled(component);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public boolean isEnabled() {
11: return other.isEnabled();
View Full Code Here
isPressed
public boolean isPressed()
Indicates if button has been pressed.
- true if the button has been pressed
View More Examples of isPressed()
1: if (c instanceof AbstractButton) {
2: ButtonModel model = ((AbstractButton)c).getModel();
3: ...
4: pressed = model.isPressed();
5: }
6: if (pressed) {
7: horizontalColor = Color.RED;
View Full Code Here
1: AbstractButton abstractButton = (AbstractButton)changeEvent.getSource();
2: ButtonModel buttonModel = abstractButton.getModel();
3: ...
4: boolean armed = buttonModel.isArmed();
5: ...
6: boolean pressed = buttonModel.isPressed();
7: boolean selected = buttonModel.isSelected();
View Full Code Here
1: (AbstractButton)changeEvent.getSource();
2: ButtonModel buttonModel = abstractButton.getModel();
3: ...
4: boolean armed = buttonModel.isArmed();
5: ...
6: boolean pressed = buttonModel.isPressed();
7: boolean selected = buttonModel.isSelected();
View Full Code Here
1: AbstractButton aButton = (AbstractButton)changEvent.getSource();
2: ButtonModel aModel = aButton.getModel();
3: boolean armed = aModel.isArmed();
4: ...
5: boolean pressed = aModel.isPressed();
6: boolean selected = aModel.isSelected();
7: System.out.println("Changed: " + armed + "/" + pressed + "/" +
8: selected);
View Full Code Here
isRollover
public boolean isRollover()
Indicates that the mouse is over the button.
- true if the mouse is over the button
View More Examples of isRollover()
1: if(Boolean.TRUE.equals(p))
2: r&=isEnabled()&&model.isRollover();
3: }
4: ...
5: Color r;
6: if(isEnabled()&&model.isRollover()&&BuLib.isMetal())
7: r=new ColorUIResource(192,192,208);
8: ...
9:
10: if(!model.isRollover()&&
11: !model.isSelected()&&
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: {
6: protected void drawControl (ButtonModel model, Graphics g, int x, int y, Component c)
7: {
8: ...
9: boolean selected = model.isSelected();
10: boolean rollover = model.isRollover();
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public boolean isRollover() {
11: return other.isRollover();
View Full Code Here
isSelected
public boolean isSelected()
Indicates if the button has been selected. Only needed for
certain types of buttons - such as radio buttons and check boxes.
- true if the button is selected
View More Examples of isSelected()
1: AbstractButton abstractButton = (AbstractButton)actionEvent.getSource();
2: boolean selected = abstractButton.getModel().isSelected();
3: System.out.println("Action - selected=" + selected + "\n");
4: ...
5: AbstractButton abstractButton = (AbstractButton)changeEvent.getSource();
6: ButtonModel buttonModel = abstractButton.getModel();
7: ...
8: boolean armed = buttonModel.isArmed();
9: boolean pressed = buttonModel.isPressed();
10: ...
11: boolean selected = buttonModel.isSelected();
View Full Code Here
1: (AbstractButton)actionEvent.getSource();
2: boolean selected = abstractButton.getModel().isSelected();
3: String newLabel = (selected ? SELECTED_LABEL : DESELECTED_LABEL);
4: ...
5: (AbstractButton)changeEvent.getSource();
6: ButtonModel buttonModel = abstractButton.getModel();
7: ...
8: boolean armed = buttonModel.isArmed();
9: boolean pressed = buttonModel.isPressed();
10: ...
11: boolean selected = buttonModel.isSelected();
View Full Code Here
1: AbstractButton aButton = (AbstractButton)changEvent.getSource();
2: ButtonModel aModel = aButton.getModel();
3: boolean armed = aModel.isArmed();
4: ...
5: boolean pressed = aModel.isPressed();
6: boolean selected = aModel.isSelected();
7: System.out.println("Changed: " + armed + "/" + pressed + "/" +
8: selected);
9: }
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: {
6: protected void drawControl (ButtonModel model, Graphics g, int x, int y, Component c)
7: {
8: ...
9: boolean armed = model.isArmed();
10: boolean selected = model.isSelected();
11: boolean rollover = model.isRollover();
View Full Code Here
View More Examples of removeActionListener(ActionListener l)
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void removeActionListener(ActionListener l) {
13: inner.removeActionListener(l);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void removeActionListener(ActionListener l) {
11: other.removeActionListener(l);
View Full Code Here
View More Examples of removeChangeListener(ChangeListener l)
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void removeChangeListener(ChangeListener l) {
13: inner.removeChangeListener(l);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void removeChangeListener(ChangeListener l) {
11: other.removeChangeListener(l);
View Full Code Here
View More Examples of removeItemListener(ItemListener l)
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void removeItemListener(ItemListener l) {
13: inner.removeItemListener(l);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void removeItemListener(ItemListener l) {
11: other.removeItemListener(l);
View Full Code Here
setActionCommand
public void setActionCommand(String s)
Sets the actionCommand string that gets sent as part of the
event when the button is pressed.
s - the String that identifies the generated event
View More Examples of setActionCommand(String s)
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void setActionCommand(String s) {
13: inner.setActionCommand(s);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void setActionCommand(String s) {
11: other.setActionCommand(s);
View Full Code Here
setArmed
public void setArmed(boolean b)
Marks the button as "armed". If the mouse button is
released while it is over this item, the button's action event
fires. If the mouse button is released elsewhere, the
event does not fire and the button is disarmed.
b - true to arm the button so it can be selected
View More Examples of setArmed(boolean b)
1: {
2: ButtonModel bm = ab.getModel();
3: if (bm.isPressed())
4: ...
5: if( r.contains( event.getPoint() ) )
6: bm.setArmed( true );
7: else
8: ...
9: bm.setArmed( false );
10: }
11: ...
12: {
13: ButtonModel bm = ab.getModel();
View Full Code Here
1: public void menuSelectionChanged(boolean isIncluded) {
2: ButtonModel model = getModel();
3: if(model.isArmed() != isIncluded) {
4: ...
5: model.setArmed(isIncluded);
6: }
7:
8: if (isIncluded) {
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: AbstractButton button = (AbstractButton) e.getSource();
6: ButtonModel model = button.getModel();
7: ...
8: model.setArmed(false);
9:
10: ...
11: AbstractButton button = (AbstractButton) e.getSource();
12: ButtonModel model = button.getModel();
View Full Code Here
setEnabled
public void setEnabled(boolean b)
Enables or disables the button.
b - true to enable the button
View More Examples of setEnabled(boolean b)
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: setFocusable(b);
11: other.setEnabled(b);
View Full Code Here
setGroup
public void setGroup(ButtonGroup group)
Identifies the group this button belongs to --
needed for radio buttons, which are mutually
exclusive within their group.
group - the ButtonGroup this button belongs to
View More Examples of setGroup(ButtonGroup group)
1: import ;
2: import ;
3: import ;
4: ...
5:
6: public class MyButtonModel implements ButtonModel {
7:
8: ...
9: private ButtonModel inner;
10:
11: ...
12: public void setGroup(ButtonGroup group) {
13: inner.setGroup(group);
View Full Code Here
1: "MenuAnswerWeight.gif");
2: private ButtonModel oldModel;
3: public Dimension getDefaultSize() {
4: ...
5: DefaultButtonModel bm = new LButtonModel(this);
6: bm.setGroup(((DefaultButtonModel) getModel()).getGroup());
7: setModel(bm);
8: ...
9: setFocusable(true);
10: oldModel.setGroup(((DefaultButtonModel) getModel()).getGroup());
11: setModel(oldModel);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void setGroup(ButtonGroup group) {
11: other.setGroup(group);
View Full Code Here
1: import ;
2: import ;
3:
4: ...
5: public void testRejectsButtonGroup() {
6: ButtonModel model = new RadioButtonAdapter(new ValueHolder(), "wow");
7: ButtonGroup group = new ButtonGroup();
8: ...
9: try {
10: model.setGroup(group);
11: ...
12: fail("RadioButtonAdapter.setGroup(ButtonGroup) must reject all ButtonGroups.");
View Full Code Here
setMnemonic
public void setMnemonic(int key)
Sets the keyboard mnemonic (shortcut key or
accelerator key) for this button.
key - an int specifying the accelerator key
View More Examples of setMnemonic(int key)
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void setMnemonic(int key) {
11: other.setMnemonic(key);
View Full Code Here
setPressed
public void setPressed(boolean b)
Sets the button to pressed or unpressed.
b - true to set the button to "pressed"
View More Examples of setPressed(boolean b)
1: import ;
2: import ;
3: import ;
4: ...
5: AbstractButton button = (AbstractButton) e.getSource();
6: ButtonModel model = button.getModel();
7: model.setArmed(false);
8: ...
9: AbstractButton button = (AbstractButton) e.getSource();
10: ButtonModel model = button.getModel();
11: model.setArmed(true);
12: ...
13: model.setPressed(true);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void setPressed(boolean b) {
11: other.setPressed(b);
View Full Code Here
setRollover
public void setRollover(boolean b)
Sets or clears the button's rollover state
b - true to turn on rollover
View More Examples of setRollover(boolean b)
1: {
2: ButtonModel bm = ab.getModel();
3: if (bm.isPressed())
4: ...
5: {
6: ButtonModel bm = ab.getModel();
7: bm.setArmed( true );
8: ...
9: {
10: ButtonModel bm = ab.getModel();
11: bm.setPressed ( false );
12: ...
13: if( ab.getRolloverIcon() != null )
14: bm.setRollover( true );
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: AbstractButton button = (AbstractButton) e.getSource();
6: ButtonModel model = button.getModel();
7: model.setArmed(false);
8: ...
9: AbstractButton button = (AbstractButton) e.getSource();
10: ButtonModel model = button.getModel();
11: model.setArmed(true);
12: ...
13: if (button.isRolloverEnabled())
14: model.setRollover(true);
View Full Code Here
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void setRollover(boolean b) {
11: other.setRollover(b);
View Full Code Here
setSelected
public void setSelected(boolean b)
Selects or deselects the button.
b - true selects the button,
false deselects the button.
View More Examples of setSelected(boolean b)
1: }
2: private class TristateDecorator implements ButtonModel {
3: ...
4: private final ButtonModel other;
5:
6: ...
7: private TristateDecorator(ButtonModel other) {
8: this.other = other;
9: ...
10: public void setSelected(boolean b) {
11: other.setSelected(b);
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: Enumeration en = buttonGroup.getElements();
6: ButtonModel model = null;
7: while (en.hasMoreElements()) {
8: ...
9: if (actionCommand.equals(model.getActionCommand())) {
10: model.setSelected(true);
11: break;
View Full Code Here
1:
2: if (init > 0) authenticButton.setSelected(true);
3: ...
4: else if (init < 0) pollutedButton.setSelected(true);
5: else rateButton.setEnabled(false);
6: ...
7:
8: misleadingNameBox.setSelected(true);
9: misleadingBitrateBox.setSelected(true);
10: ...
11:
12: public ButtonModel getSelection() { throw new UnsupportedOperationException(); }
View Full Code Here
1: import ;
2: import ;
3: import ;
4: ...
5: if (action != null && !action.equals(otherAction)) {
6: tb.setSelected(false);
7: ...
8: ButtonModel bm = tb.getModel();
9: bm.setRollover(false);
10: ...
11: bm.setSelected(false);
View Full Code Here