Java Code Examples for javax.swing.AbstractButton#setSelected()

The following examples show how to use javax.swing.AbstractButton#setSelected() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ButtonHelper.java    From javamoney-examples with Apache License 2.0 6 votes vote down vote up
/**
 * This method builds the specified button according to the specified
 * parameters.
 *
 * @param button The button to build.
 * @param text The text displayed on the button.
 * @param icon The icon to use.
 * @param handler The action listener that monitors the buttons events.
 * @param command The action command used when the button is clicked.
 * @param group The group the button should belong to.
 * @param selected The initial selected state of the button.
 * @param tip The tool tip to display.
 */
public
static
void
buildButton(AbstractButton button, String text, Icon icon,
    ActionListener handler, String command, ButtonGroup group,
    boolean selected, String tip)
{
  button.addActionListener(handler);
  button.setActionCommand(command);
  button.setIcon(icon);
  button.setSelected(selected);
  button.setText(text);
  button.setToolTipText(tip);

  if(group != null)
  {
    group.add(button);
  }
}
 
Example 2
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
protected void parallelSpeedUpActionPerformed(ActionEvent evt) {
    AbstractButton button = (AbstractButton) evt.getSource();
    boolean selected = button.isSelected();

    String confStr = translate("message.confirm.parallel") + "\r\n";
    if (selected) {
        confStr += " " + translate("message.confirm.on");
    } else {
        confStr += " " + translate("message.confirm.off");
    }
    if (View.showConfirmDialog(null, confStr, translate("message.parallel"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        Configuration.parallelSpeedUp.set(selected);
    } else {
        button.setSelected(Configuration.parallelSpeedUp.get());
    }
}
 
Example 3
Source File: SwingStrategyUI.java    From atdl4j with MIT License 6 votes vote down vote up
@Override
protected void applyRadioGroupRules() {
	if ( radioGroupMap != null )
	{
		for ( ButtonGroup tempSwingRadioButtonListener : radioGroupMap.values() )
		{
			// -- If no RadioButtons within the radioGroup are selected, then first one in list will be selected --
			if (tempSwingRadioButtonListener.getSelection() == null){
				AbstractButton ab = tempSwingRadioButtonListener.getElements().nextElement();
				if (ab != null) {
					ab.setSelected(true);
				}
			}
		}
	}
}
 
Example 4
Source File: CompositeMenuToggleButton.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Selects the given action in the menu. This methods also updates the selection status of the
 * toggle button.
 *
 * @param action
 *            the action which should be selected
 */
public void setSelected(Action action) {
	Enumeration<AbstractButton> menuEnum = popupMenuGroup.getElements();
	boolean found = false;
	while (menuEnum.hasMoreElements()) {
		AbstractButton button = menuEnum.nextElement();
		if (action == button.getAction()) {
			button.setSelected(true);
			found = true;
		} else {
			button.setSelected(false);
		}
	}
	if (found) {
		setFont(getFont().deriveFont(Font.BOLD));
		updateSelectionStatus();
	} else {
		setFont(getFont().deriveFont(Font.PLAIN));
		clearMenuSelection();
	}
}
 
Example 5
Source File: MockComponent.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Temporarily massage this component so it is visible, enabled, unselected,
 * unfocused, etc.
 */
private void storeState(JComponent c) {
	if (c instanceof AbstractButton) {
		AbstractButton b = (AbstractButton) c;
		b.putClientProperty(WAS_SELECTED, new Boolean(b.isSelected()));
		b.putClientProperty(WAS_FOCUS_PAINTED, new Boolean(b.isSelected()));
		b.setSelected(false);
		b.setFocusPainted(false);
	}
	if (c.isEnabled() == false) {
		c.putClientProperty(WAS_ENABLED, new Boolean(c.isEnabled()));
		c.setEnabled(true);
	}
	if (c.isVisible() == false) {
		c.putClientProperty(WAS_VISIBLE, new Boolean(c.isVisible()));
		c.setVisible(true);
	}
	for (int a = 0; a < c.getComponentCount(); a++) {
		if (c.getComponent(a) instanceof JComponent) {
			storeState((JComponent) c.getComponent(a));
		}
	}
}
 
Example 6
Source File: TestCaseToolBar.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private void selectABrowser() {
    String browser = getPreviouslySelectedBrowser();
    if (browser == null) {
        browser = RunManager.getGlobalSettings().getBrowser();
    }
    if (browser != null) {
        for (Enumeration<AbstractButton> buttons = browserSelectButtonGroup.getElements(); buttons.hasMoreElements();) {
            AbstractButton button = buttons.nextElement();
            if (button.getActionCommand().equals(browser)) {
                button.setSelected(true);
            }
        }
    } else {
        browserSelectButtonGroup.setSelected(browserSelectButtonGroup.getElements().nextElement().getModel(), true);
    }
}
 
Example 7
Source File: ToggleButtonGroup.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void add(AbstractButton b) {
    if (b == null) {
        return;
    }
    buttons.addElement(b);

    if (b.isSelected()) {
        if (modifiedSelection == null) {
            modifiedSelection = b.getModel();
        } else {
            b.setSelected(false);
        }
    }

    b.getModel().setGroup(this);
}
 
Example 8
Source File: SearchPatternController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Bind an abstract button (usually checkbox) to a SearchPattern option.
 *
 * @param option Option whose value the button should represent.
 * @param button Button to control and display the option.
 */
public void bind(@NonNull final Option option,
        @NonNull final AbstractButton button) {
    Parameters.notNull("option", option);                           //NOI18N
    Parameters.notNull("button", button);                           //NOI18N

    if (bindings.containsKey(option)) {
        throw new IllegalStateException(
                "Already binded with option " + option);           // NOI18N
    }

    bindings.put(option, button);
    button.setSelected(getOption(option));
    button.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            setOption(option, button.isSelected());
        }
    });
}
 
Example 9
Source File: SearchPatternController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Set value of a search pattern option. Bound abstract button will be
 * selected or deselected accordingly.
 */
private void setOption(@NonNull Option option, boolean value) {
    Parameters.notNull("option", option);                           //NOI18N
    options.put(option, value);
    AbstractButton button = bindings.get(option);
    if (button != null) {
        button.setSelected(value);
    }
    if (option == Option.REGULAR_EXPRESSION) {
        if ((matchType == MatchType.REGEXP) != value) {
            setMatchType(value ? MatchType.REGEXP : MatchType.LITERAL);
        }
        updateValidity();
    }
    fireChange();
}
 
Example 10
Source File: PauseAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static final void updateButton(AbstractButton btnResume) {
    if (isSuspended()) {
        int pending = Integer.getInteger("org.netbeans.io.pending", 0); // NOI18N
        btnResume.setText(Bundle.MSG_Resume(pending));
        btnResume.setSelected(true);
    } else {
        btnResume.setText(null);
        btnResume.setSelected(false);
    }
}
 
Example 11
Source File: AlwaysEnabledAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateItemsSelected() {
    boolean selected = isPreferencesSelected();
    if (menuItem != null) {
        menuItem.setSelected(selected);
    }
    if (popupItem != null) {
        popupItem.setSelected(selected);
    }
    if (toolbarItems != null) {
        for(AbstractButton b : toolbarItems) {
            b.setSelected(selected);
        }
    }
}
 
Example 12
Source File: LogTopComponent.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void myInit() {
    tabManagers = new ArrayList<>();

    // create the first tab
    addTable(LogFilter.createDefaultTab());

    // activate the selected button
    for (Enumeration<AbstractButton> buttons = btGrpLogLevel.getElements(); buttons.hasMoreElements();) {
        AbstractButton button = buttons.nextElement();

        if (button.getActionCommand().equals(rowFilter.getLogLevel().toString())) {
            button.setSelected(true);
        }
    }
}
 
Example 13
Source File: ToggleMasterSlaveRelationShipsAction.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this action with the specified tree table panel.
 * @param panel the graph panel to which this action applies.
 */
public ToggleMasterSlaveRelationShipsAction(final MasterSlaveRelationShipsHandler panel) {
  this.panel = panel;
  setupIcon("/org/jppf/ui/resources/sparkle.png");
  setupNameAndTooltip(BTN_NAME + ".on");
  //setupTooltip(BTN_NAME + ".on");
  button = (AbstractButton) ((OptionElement) panel).findFirstWithName("/" + BTN_NAME).getUIComponent();
  button.setSelected(true);
}
 
Example 14
Source File: SettingsGui.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Binds the selection state of the specified abstract button (which can be e.g. a {@link XCheckBox} or a {@link JCheckBoxMenuItem}) to the specified
 * {@link IBoolSetting} from the specified {@link ISettingsBean}.
 * 
 * @param button button whose state to be bounded
 * @param setting setting to control the visibility of the component
 * @param settings settings bean storing the setting
 */
public static void bindSelectionToSetting( final AbstractButton button, final IBoolSetting setting, final ISettingsBean settings ) {
	final ISettingChangeListener scl = new ISettingChangeListener() {
		@Override
		public void valuesChanged( final ISettingChangeEvent event ) {
			if ( event.affected( setting ) )
				button.setSelected( event.get( setting ) );
		}
	};
	addBindExecuteScl( scl, settings, setting.selfSet(), button );
}
 
Example 15
Source File: MockComponent.java    From pumpernickel with MIT License 5 votes vote down vote up
/** Restore this component back to its original goodness. */
private void restoreState(JComponent c) {
	if (c instanceof AbstractButton) {
		AbstractButton b = (AbstractButton) c;
		if (b.getClientProperty(WAS_SELECTED) != null) {
			b.setSelected(((Boolean) b.getClientProperty(WAS_SELECTED))
					.booleanValue());
			b.putClientProperty(WAS_SELECTED, null);
		}
		if (b.getClientProperty(WAS_FOCUS_PAINTED) != null) {
			b.setFocusPainted(((Boolean) b
					.getClientProperty(WAS_FOCUS_PAINTED)).booleanValue());
			b.putClientProperty(WAS_FOCUS_PAINTED, null);
		}
	}
	if (c.getClientProperty(WAS_ENABLED) != null) {
		c.setEnabled(((Boolean) c.getClientProperty(WAS_ENABLED))
				.booleanValue());
		c.putClientProperty(WAS_ENABLED, null);
	}
	if (c.getClientProperty(WAS_VISIBLE) != null) {
		c.setVisible(((Boolean) c.getClientProperty(WAS_VISIBLE))
				.booleanValue());
		c.putClientProperty(WAS_VISIBLE, null);
	}
	for (int a = 0; a < c.getComponentCount(); a++) {
		if (c.getComponent(a) instanceof JComponent) {
			restoreState((JComponent) c.getComponent(a));
		}
	}
}
 
Example 16
Source File: ButtonListener.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void mouseExited(MouseEvent e) {
	super.mouseExited(e);
	AbstractButton button = (AbstractButton) e.getSource();
	button.getModel().setRollover(false);
	button.setSelected(false);
}
 
Example 17
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
protected void autoDeobfuscationActionPerformed(ActionEvent evt) {
    AbstractButton button = (AbstractButton) evt.getSource();
    boolean selected = button.isSelected();

    if (View.showConfirmDialog(mainFrame.getPanel(), translate("message.confirm.autodeobfuscate") + "\r\n" + (selected ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        Configuration.autoDeobfuscate.set(selected);
        mainFrame.getPanel().autoDeobfuscateChanged();
    } else {
        button.setSelected(Configuration.autoDeobfuscate.get());
    }
}
 
Example 18
Source File: GridBagCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Updates the state of those pushbuttons in the left
 * vertical tool box that need to indicate the special "ambiguous"
 * state marking that some of the currently selected components
 * have the respective property set while some do not.
 */
private void updateButton(AbstractButton button, boolean nonEmptySelection, boolean allSelectedUnambiguous, String iconWarning, String toolTipWarning, String iconNormal, String toolTipNormal) {
    button.setSelected(allSelectedUnambiguous);
    if(nonEmptySelection && !allSelectedUnambiguous) {
        button.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/layoutsupport/griddesigner/resources/" + iconWarning, false)); // NOI18N
        button.setToolTipText(NbBundle.getMessage(GridBagCustomizer.class, "GridBagCustomizer." + toolTipWarning)); // NOI18N
    } else {
        button.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/layoutsupport/griddesigner/resources/" + iconNormal, false)); // NOI18N
        button.setToolTipText(NbBundle.getMessage(GridBagCustomizer.class, "GridBagCustomizer." + toolTipNormal)); // NOI18N
    }
}
 
Example 19
Source File: ToggleLayoutAction.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this action with the specified tree table panel.
 * @param panel the graph panel to which this action applies.
 */
public ToggleLayoutAction(final GraphOption panel) {
  super(panel);
  setupIcon("/org/jppf/ui/resources/layout.gif");
  setupNameAndTooltip("graph.toggle.layout.on");
  button = (AbstractButton) panel.findFirstWithName("/graph.toggle.layout").getUIComponent();
  button.setSelected(true);
}
 
Example 20
Source File: AppConfigDialog.java    From defense-solutions-proofs-of-concept with Apache License 2.0 4 votes vote down vote up
private void copySettingsToUI() {
    /**
     * If one of the JSpinners is currently focused, it will keep its UI value
     * even if we set its value here. Therefore, have this dialog request the focus.
     */
    this.requestFocus();

    //Set field values from appConfigController
    String username = appConfigController.getUsername();
    if (null != username) {
        jTextField_username.setText(username);
    }
    String vehicleType = appConfigController.getVehicleType();
    if (null != username) {
        jTextField_vehicleType.setText(vehicleType);
    }
    String uniqueId = appConfigController.getUniqueId();
    if (null != uniqueId) {
        jTextField_uniqueId.setText(uniqueId);
    }
    String sic = appConfigController.getSic();
    if (null != sic) {
        jTextField_sic.setText(sic);
    }
    int port = appConfigController.getPort();
    if (-1 < port) {
        jSpinner_messagingPort.setValue(port);
    }
    int positionMessageInterval = appConfigController.getPositionMessageInterval();
    if (-1 < positionMessageInterval) {
        jSpinner_positionMessageInterval.setValue(positionMessageInterval);
    }
    int vehicleStatusMessageInterval = appConfigController.getVehicleStatusMessageInterval();
    if (-1 < vehicleStatusMessageInterval) {
        jSpinner_vehicleStatusMessageInterval.setValue(vehicleStatusMessageInterval);
    }
    double speedMultiplier = appConfigController.getSpeedMultiplier();
    if (0 < speedMultiplier) {
        jSpinner_speedMultiplier.setValue(speedMultiplier);
    }
    jCheckBox_showMessageLabels.setSelected(appConfigController.isShowMessageLabels());
    jCheckBox_decorated.setSelected(appConfigController.isDecorated());
    jCheckBox_showLocalTimeZone.setSelected(appConfigController.isShowLocalTimeZone());
    if (appConfigController.isShowMgrs()) {
        jRadioButton_mgrs.setSelected(true);
    } else {
        jRadioButton_lonLat.setSelected(true);
    }
    Enumeration<AbstractButton> headingUnitsButtons = buttonGroup_headingUnits.getElements();
    while (headingUnitsButtons.hasMoreElements()) {
        AbstractButton button = headingUnitsButtons.nextElement();
        if (button.getActionCommand().equals(Integer.toString(appConfigController.getHeadingUnits()))) {
            button.setSelected(true);
            break;
        }
    }
    jComboBox_geomessageVersion.setSelectedItem(appConfigController.getGeomessageVersion());
}