List of utility methods to do JButton Settings
void | ScaleButtonIcon(JToggleButton btn, int width, int height, int fontsize) Scale Button Icon btn.setMargin(null); int iconWidth = width; int iconHeigth = height; if (btn.getText() != null && !btn.getText().isEmpty()) { Font font = btn.getFont(); btn.setFont(new Font(font.getName(), font.getStyle(), fontsize)); FontMetrics fm = btn.getFontMetrics(font); btn.setHorizontalTextPosition(JButton.CENTER); ... |
String | SelectedOptionButton(Container container) Selected Option Button for (Component optIterator : container.getComponents()) { if (optIterator instanceof JRadioButton) { JRadioButton optSelected = (JRadioButton) optIterator; if (optSelected.isSelected()) { return optSelected.getActionCommand(); return ""; |
File | selectFile(final int openMode, final String title, final String buttonText, final String lastDirectoryUsed, final Component parent, final String suffix, final String description) Function to open a JFileChooser and set it properly. JFileChooser chooser = new JFileChooser(lastDirectoryUsed); chooser.setFileHidingEnabled(false); chooser.setDialogTitle(title); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isDirectory()) { return true; ... |
void | selectWithoutNotifyingListeners(AbstractButton ab, boolean selected) select Without Notifying Listeners ItemListener[] il = ab.getItemListeners(); if (il != null) { for (ItemListener i : il) ab.removeItemListener(i); ActionListener[] al = ab.getActionListeners(); if (al != null) { for (ActionListener i : al) ... |
void | setAction(AbstractButton btn, ActionListener listener, String actionCommand) set Action btn.addActionListener(listener); btn.setActionCommand(actionCommand); |
void | setAllEnabled(final ButtonGroup buttonGroup, final boolean enabled) Enables (or disables) all the buttons in a button group. for (final AbstractButton button : Collections.list(buttonGroup.getElements())) { button.setEnabled(enabled); |
void | setAutoMnemonic(AbstractButton button) Sets the mnemonic for the given button using jEdit convention, taking the letter after the dollar. String label = button.getText(); char mnemonic; int index = label.indexOf('$'); if (index != -1 && label.length() - index > 1) { mnemonic = Character.toLowerCase(label.charAt(index + 1)); label = label.substring(0, index).concat(label.substring(++index)); } else { mnemonic = '\0'; ... |
void | setBtnValue(ButtonGroup group, String value) set Btn Value for (Enumeration<AbstractButton> e = group.getElements(); e.hasMoreElements();) { AbstractButton btn = e.nextElement(); if (btn.getActionCommand().equals(value)) { group.setSelected(btn.getModel(), true); break; |
void | setButton(AbstractButton button, Icon icon, ActionListener buttonListener) Set Button using given arguments. button.setIcon(icon); button.addActionListener(buttonListener); button.setContentAreaFilled(false); |
void | setButtonContentMargin(AbstractButton button, Insets margin) Sets the content margin of a button (for Nimbus L&F). UIDefaults defaults = new UIDefaults(); defaults.put("Button.contentMargins", margin); defaults.put("ToggleButton.contentMargins", margin); button.putClientProperty("Nimbus.Overrides", defaults); |