List of utility methods to do JButton Settings
void | setScaledIcon(final AbstractButton button, final ImageIcon icon, final int orientation, final double scale) Sets the button's default icon, scales it to a given factor of the button's preferred size and aligns it to the given orientation. final Dimension preferredSize = button.getPreferredSize(); final Insets margin = button.getMargin(); final int minimumSize = Math.min(preferredSize.width - margin.left - margin.right, preferredSize.height - margin.top - margin.bottom); int size = minimumSize; final double actualScale = Math.abs(scale); if (actualScale != 1) { final double scaledSize = actualScale * size; ... |
void | setSelected(final AbstractButton abstractButton, final boolean isSelected) set Selected doSetSelected(abstractButton, isSelected); |
void | setSelectedButton(ButtonGroup group, int index) set Selected Button Enumeration<AbstractButton> enumeration = group.getElements(); int i = 0; while (enumeration.hasMoreElements()) { AbstractButton button = enumeration.nextElement(); group.setSelected(button.getModel(), index == i); i++; |
void | setSelectedSilently(AbstractButton x, boolean b) set Selected Silently ActionListener[] al = x.getActionListeners(); if (al != null && al.length > 0) { for (ActionListener a : al) x.removeActionListener(a); ItemListener[] il = x.getItemListeners(); if (il != null && il.length > 0) { for (ItemListener a : il) ... |
void | setToggleGroups(final JToggleButton... buttons) Bind the toggle buttons into a group in which only one can be selected. for (int i = 0; i < buttons.length; i++) { final int t = i; buttons[i].addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean flag = buttons[t].isSelected(); if (flag) { for (int i = 0; i < buttons.length; i++) ... |
void | setToggling(AbstractButton b) Set the specified button such that it alternates between being selected and not whenever it is pushed. if (_toggler == null) { _toggler = new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton but = (AbstractButton) event.getSource(); but.setSelected(!but.isSelected()); }; b.addActionListener(_toggler); |
void | setWithoutNotifyingListeners(AbstractButton button, boolean selected) set Without Notifying Listeners if (button == null) return; Action a = button.getAction(); String text = button.getText(); String tooltip = button.getToolTipText(); ItemListener[] il = button.getItemListeners(); if (il != null) { for (ItemListener x : il) ... |
int | showJFileChooser(javax.swing.JFileChooser chooser, java.awt.Component parent, java.lang.String approveButtonText) Utility method for avoiding of memory leak in JDK 1.3 / JFileChooser.showDialog(...) if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG); Frame frame = null; Dialog parentDlg = null; if (parent instanceof Dialog) parentDlg = (Dialog) parent; ... |
int | showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText) Displays the given file chooser. if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG); Frame frame = (parent instanceof Frame) ? (Frame) parent : (Frame) javax.swing.SwingUtilities.getAncestorOfClass(java.awt.Frame.class, parent); String title = chooser.getDialogTitle(); if (title == null) { ... |
int | showOptions(int width, int type, String title, String text, Object... buttons) Shows a message with options presented as an array of buttons. return JOptionPane.showOptionDialog(null, String.format("<html><body style=\"width:%dpx\">%s</body></html>", normalizeMessageWidth(width), text), title, JOptionPane.DEFAULT_OPTION, normalizeIconType(type), null, buttons, buttons[0]) + 1; |