下面列出了javax.swing.JButton#setSelected ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Constructs a Swing JButton using current builder values. Values that must be set: title,
* actionlistener
*/
public JButton build() {
checkNotNull(title);
final JButton button = new JButton(title);
Optional.ofNullable(clickAction)
.ifPresent(listener -> button.addActionListener(e -> clickAction.accept(button)));
Optional.ofNullable(toolTip).ifPresent(button::setToolTipText);
button.setSelected(selected);
button.setEnabled(enabled);
if (biggerFont > 0) {
button.setFont(
new Font(
button.getFont().getName(),
button.getFont().getStyle(),
button.getFont().getSize() + biggerFont));
}
return button;
}
private JButton createButton(String toolTipText,
ImageIcon icon,
java.awt.event.ActionListener actionListener)
{
JButton btn = new JButton();
btn.setMargin(new Insets(0, 0, 0, 0));
btn.setPreferredSize(new Dimension(30, 30));
btn.setIcon(icon);
btn.setMinimumSize(new Dimension(30, 30));
btn.setVerticalTextPosition(SwingConstants.BOTTOM);
btn.setSelected(false);
btn.setToolTipText(toolTipText);
btn.setHorizontalTextPosition(SwingConstants.CENTER);
btn.setFont(new java.awt.Font("SansSerif", 0, 10));
btn.setMaximumSize(new Dimension(30, 30));
btn.addActionListener(actionListener);
return btn;
}
private PresenterUpdater(int type, Action action) {
if (action == null) {
throw new IllegalArgumentException("action must not be null"); // NOI18N
}
this.type = type;
this.actionName = (String) action.getValue(Action.NAME);
this.action = action;
if (type == TOOLBAR) {
presenter = new JButton();
useActionSelectedProperty = false;
} else { // MENU or POPUP
useActionSelectedProperty = (action.getValue(AbstractEditorAction.PREFERENCES_KEY_KEY) != null);
if (useActionSelectedProperty) {
presenter = new LazyJCheckBoxMenuItem();
presenter.setSelected(isActionSelected());
} else {
presenter = new LazyJMenuItem();
}
}
action.addPropertyChangeListener(WeakListeners.propertyChange(this, action));
if (type == MENU) {
listenedContextActions = new WeakSet<Action>();
EditorRegistryWatcher.get().registerPresenterUpdater(this); // Includes notification of active component
} else {
listenedContextActions = null;
}
presenter.addActionListener(this);
updatePresenter(null); // Not active yet => mark updates pending
}
private void selectPad(final Pad selectedPad, final int padId, final JButton button) {
final JButton lastSelected = padButtons[selectedPad.getElementIndex()];
lastSelected.setSelected(false);
selectedPad.setElementIndex(padId);
currentlySelectedPad = selectedPad;// remember currently selected pad
button.setSelected(true);
// System.out.println("Pad " + padId + " pressed!");
refreshParamsArea();
}