List of utility methods to do JButton
void | reduceNimbusButtonMargin(final JButton button) Reduce the margins around the content of a button for the Nimbus look and feel UIDefaults buttonDefaults = new UIDefaults(); buttonDefaults.put("Button.contentMargins", new Insets(6, 6, 6, 6)); button.putClientProperty("Nimbus.Overrides", buttonDefaults); button.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.FALSE); |
void | registerCancelButton(final JButton cancelButton) Register the escape key so that it can be used to cancel the associated JDialog. KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); JDialog dialog = (JDialog) SwingUtilities.getWindowAncestor(cancelButton); dialog.getRootPane().registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { cancelButton.doClick(); }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); ... |
void | removeAllActionListeners(JButton button) remove All Action Listeners ActionListener[] listeners = button.getActionListeners(); for (int i = 0; i < listeners.length; i++) { button.removeActionListener(listeners[i]); |
void | removeAllListeners(JButton bouton) remove All Listeners for (ActionListener al : bouton.getActionListeners()) {
bouton.removeActionListener(al);
|
void | removeMargins(JButton button) Removes all extra spacing around the button so other components are layed out right next to it. button.setBorder(null);
button.setBorderPainted(false);
button.setMargin(new Insets(0, 0, 0, 0));
|
void | renderImageOnly(JButton button) Changes style formatting of a button so that only the images will show; no additional drawing. button.setBorderPainted(false); button.setContentAreaFilled(false); button.setFocusPainted(false); button.setOpaque(false); |
void | setButtonNo(JButton anButton) setButtonOk anButton.setText(BUTTON_NO); |
void | setCancelButton(final JRootPane rp, final JButton b) set Cancel Button rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); rp.getActionMap().put("cancel", new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent ev) { b.doClick(); }); ... |
void | setEmptyBorder(JButton button, int paddingTop, int paddingLeft, int paddingBottom, int paddingRight) set Empty Border if (button != null) {
Border emptyBorder = BorderFactory.createEmptyBorder(paddingTop, paddingLeft, paddingBottom,
paddingRight);
button.setBorder(emptyBorder);
|
void | setEnable(boolean b, JButton... bs) set Enable for (JButton button : bs) {
button.setEnabled(b);
|