List of utility methods to do JButton
void | copyButtonWidth(JButton toButton, JButton fromButton) Makes a button as wide as another given button. toButton.setPreferredSize(fromButton.getPreferredSize()); toButton.setMaximumSize(fromButton.getMaximumSize()); |
void | doButtonClick(JButton button) Performs visually visible click on the button component. button.doClick(BUTTON_CLICK_TIME); |
void | drawCharacter(JPanel contentPane, ActionListener listener, String url, int x, int y, List draw Character BufferedImage originalImage; try { try { originalImage = ImageIO.read(new URL(url)); } catch (Exception e) { originalImage = ImageIO.read(new URL("http://s3.amazonaws.com/MinecraftSkins/char.png")); int type = BufferedImage.TYPE_INT_ARGB; ... |
void | enableEnter(JButton b) Enable activating button on Enter (which is replaced with spacebar for certain Look-And-Feels) b.setFocusable(true); b.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); b.getActionMap().put("enter", b.getAction()); |
void | ensureButtonWidth(JButton button, int width) Ensures a button has a specific minimum width. Dimension prefSize = button.getPreferredSize();
if (prefSize.width < width) {
prefSize.width = width;
button.setPreferredSize(prefSize);
|
void | enterPressesWhenFocused(final JButton button) Registers the enter key a JButton . button.registerKeyboardAction( button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED); button.registerKeyboardAction( button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_FOCUSED); |
void | equalizeButtons(JButton... buttons) equalize Buttons int maxWidth = 0; int maxHeight = 0; for (JButton button : buttons) { Dimension d = button.getPreferredSize(); maxWidth = Math.max(d.width, maxWidth); maxHeight = Math.max(d.height, maxHeight); Dimension d = new Dimension(maxWidth, maxHeight); ... |
void | exit(JButton aButton) exit aButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { System.exit(0); }); |
void | fixButtonWidth(JButton... buttons) fix Button Width fixButtonWidth(0, buttons); |
void | fixToolbarButtonImpl(JButton button) fix Toolbar Button Impl ButtonUI ui = button.getUI(); String clazzName = ui.getClass().getName(); if (BUTTON_UI_CLASS_NAME.equals(clazzName)) { Class<?> uiClazz = ui.getClass(); Method m = uiClazz.getDeclaredMethod("setRolloverDecoratedOnly", boolean.class); m.invoke(ui, true); m = uiClazz.getMethod("setRound", int.class); ClassLoader cl = uiClazz.getClassLoader(); ... |