Java Utililty Methods JButton Create

List of utility methods to do JButton Create

Description

The list of methods to do JButton Create are organized into topic(s).

Method

JComponentcreateButtonRow(List buttons)
Takes the given list of buttons and creates a horizontal panel containing them, with standard spacing and size.
equalizeSizes(buttons);
Box row = new Box(BoxLayout.X_AXIS);
row.setBorder(BorderFactory.createEmptyBorder(DEFAULT_BORDER, 0, DEFAULT_BORDER, 0));
Iterator buttonIt = buttons.iterator();
while (buttonIt.hasNext()) {
    row.add((JComponent) buttonIt.next());
    if (buttonIt.hasNext())
        row.add(Box.createRigidArea(new Dimension(DEFAULT_STRUT, 0))); 
...
JPanelcreateButtonsPanel(JComponent... components)
create Buttons Panel
final JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonsPanel.setOpaque(false);
for (final JComponent component : components) {
    buttonsPanel.add(component);
return buttonsPanel;
JPanelcreateCheckbox(String boxlabel, String[] buttons, boolean[] checked, ActionListener al)
Create a panel containing a checkbox.
JPanel jp = createPaletteJPanel(boxlabel);
for (int j = 0; j < buttons.length; j++) {
    JCheckBox jcb = new JCheckBox(buttons[j]);
    jcb.setActionCommand(Integer.toString(j));
    if (al != null)
        jcb.addActionListener(al);
    jcb.setSelected(checked[j]);
    jp.add(jcb);
...
JButtoncreateCustomButton(Action a)
create Custom Button
return (JButton) customize(new JButton(a));
JButtonCreateFlatButton()
Creates a new JButton with the flat appearance.
JButton button = new JButton();
makeButtonFlat(button);
return button;
JRadioButtoncreateGameRadioButton(String answer, int fontSize)
create Game Radio Button
JRadioButton btn = new JRadioButton(answer);
btn.setBackground(Color.GRAY);
btn.setForeground(Color.WHITE);
btn.setFont(new Font(" ", Font.BOLD, fontSize));
return btn;
JButtoncreateHyperlinkButton(String text, String tip, ActionListener action)
create Hyperlink Button
JButton button = new JButton();
button.setText("<html><a href=\"#\">" + text + "</a></html>");
button.setHorizontalAlignment(SwingConstants.LEFT);
button.setBorderPainted(false);
button.setBorder(BorderFactory.createEmptyBorder());
button.setOpaque(false);
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
button.setBackground(new Color(0, 0, 0, 0));
...
JButtoncreateIconButton(Class klass, String resource, String fallbackText)
Creates a JButton with an Icon from the named resource, which should be in the class loader jar file as klass.
JButton result = new JButton();
try {
    Image image = ImageIO.read(klass.getResource(resource));
    result.setIcon(new ImageIcon(image));
} catch (Exception e) {
    result.setText(fallbackText);
result.setToolTipText(fallbackText);
...
JButtoncreateIconButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)
create Icon Button
JButton btn = new JButton();
btn.setToolTipText(tooltipText);
btn.setIcon(icon);
btn.setMaximumSize(new Dimension(dimension, dimension));
btn.setMinimumSize(new Dimension(dimension, dimension));
btn.setPreferredSize(new Dimension(dimension, dimension));
btn.setMargin(new Insets(0, 0, 0, 0));
if (action != null)
...
JButtoncreateJButton(Container c, String caption, int x, int y, int width, int height, ActionListener al)
This method makes it easy (and also neat) creating a JButton and adding it to its container class.
JButton btn = new JButton(caption);
btn.setBounds(x, y, width, height);
if (al != null)
    btn.addActionListener(al);
c.add(btn);
return btn;