List of usage examples for javax.swing AbstractButton setSelected
public void setSelected(boolean b)
From source file:org.openscience.jmol.app.Jmol.java
/** * Create a button to go inside of the toolbar. By default this * will load an image resource. The image filename is relative to * the classpath (including the '.' directory if its a part of the * classpath), and may either be in a JAR file or a separate file. * * @param key The key in the resource file to serve as the basis * of lookups.//from w w w. ja v a2s .com * @return Button */ protected AbstractButton createToolbarButton(String key) { ImageIcon ii = JmolResourceHandler.getIconX(key + "Image"); AbstractButton b = new JButton(ii); String isToggleString = JmolResourceHandler.getStringX(key + "Toggle"); if (isToggleString != null) { boolean isToggle = Boolean.valueOf(isToggleString).booleanValue(); if (isToggle) { b = new JToggleButton(ii); if (key.equals("rotate")) buttonRotate = b; toolbarButtonGroup.add(b); String isSelectedString = JmolResourceHandler.getStringX(key + "ToggleSelected"); if (isSelectedString != null) { boolean isSelected = Boolean.valueOf(isSelectedString).booleanValue(); b.setSelected(isSelected); } } } b.setRequestFocusEnabled(false); b.setMargin(new Insets(1, 1, 1, 1)); Action a = null; String actionCommand = null; if (key.endsWith("Script")) { actionCommand = JmolResourceHandler.getStringX(key); a = executeScriptAction; } else { actionCommand = key; a = getAction(key); } if (a != null) { b.setActionCommand(actionCommand); b.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(b)); b.setEnabled(a.isEnabled()); } else { b.setEnabled(false); } String tip = guimap.getLabel(key + "Tip"); if (tip != null) { b.setToolTipText(tip); } return b; }
From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java
@Override public void onDomReady() { if (this.group != null && getDocument() != null && getDocument().getRootElement() instanceof SwingRoot) { buttonGroup = ((SwingRoot) SwingButton.this.getDocument().getRootElement()).getButtonGroup(group); AbstractButton button = (AbstractButton) getManagedObject(); buttonGroup.add(button);/*from ww w . j a v a 2s. c om*/ if (buttonGroup.getButtonCount() == 1) { // first button in, TODO: remove once selected="true" attribute supported button.setSelected(true); } } }
From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java
@Override public void layout() { // check type to see if it's a toggleButton if (type == Type.CHECKBOX || type == Type.RADIO) { final AbstractButton oldButton = getButton(); final AbstractButton button = new JToggleButton(); button.setText(oldButton.getText()); button.setIcon(oldButton.getIcon()); button.setEnabled(oldButton.isEnabled()); button.setSelected(this.selected); setButton(button);/*w ww.j a va 2 s .c o m*/ if (this.getOnclick() != null) { this.setOnclick(this.getOnclick()); } } final AbstractButton button = getButton(); // adjust orientation of label and icon if (this.orientation == Orient.VERTICAL) { button.setHorizontalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setVerticalTextPosition(JButton.BOTTOM); } else { button.setVerticalTextPosition(JButton.TOP); } } else { button.setVerticalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setHorizontalTextPosition(JButton.RIGHT); } else { button.setHorizontalTextPosition(JButton.LEFT); } } // Square button patch. if no label and icon is square, set min/max to square up button final Icon icon = button.getIcon(); if ("".equals(button.getText()) && icon != null && icon.getIconHeight() == icon.getIconWidth()) { Dimension dim = button.getPreferredSize(); button.setMinimumSize(new Dimension(dim.height, dim.height)); button.setPreferredSize(new Dimension(dim.height, dim.height)); } button.setToolTipText(this.getTooltiptext()); super.layout(); }
From source file:org.pentaho.ui.xul.swing.tags.SwingRadio.java
@Override public void onDomReady() { if (this.group != null && getDocument() != null && getDocument().getRootElement() instanceof SwingRoot) { ButtonGroup buttonGroup = ((SwingRoot) getDocument().getRootElement()).getButtonGroup(group); AbstractButton button = (AbstractButton) getManagedObject(); buttonGroup.add(button);/*from w w w . ja v a 2 s . com*/ if (buttonGroup.getButtonCount() == 1) { // first button in, TODO: remove once selected="true" attribute supported button.setSelected(true); } } }
From source file:pcgen.gui2.dialog.OptionsPathDialog.java
private void addRadioButton(String text, String command, ButtonGroup group, ActionListener listener, GridBagConstraints gbc) { boolean selected = command.equals(selectedDir); if (selected) { text += " (default)"; //for i18n this will need to be handled differently }// w w w. j a v a2 s .c o m AbstractButton rButton = new JRadioButton(text); rButton.setActionCommand(command); rButton.setSelected(selected); rButton.addActionListener(listener); group.add(rButton); getContentPane().add(rButton, gbc); }