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

JPanelmakeButtonPanel(Vector names, ActionListener actionListener)
make Button Panel
JPanel pane = new JPanel();
for (String s : names) {
    JButton b = makeButton(s, actionListener);
    pane.add(b);
return pane;
JButtonmakeIconButton(Icon icon, String tooltip)
make Icon Button
JButton button = new JButton(icon);
button.setToolTipText(tooltip);
button.setBackground(BLUE8);
button.setForeground(BLUE3);
button.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, new Color(0, 0, 0, 0)));
button.setFont(BIG);
return button;
JButtonmakeNavigationButton(String actionCommand, String toolTipText, String altText)
make Navigation Button
JButton button = new JButton();
button.setActionCommand(actionCommand);
button.setToolTipText(toolTipText);
button.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();
        if (actionCommand.equals(CLOSE)) {
...
JRadioButtonmakeRadioButton(String text, String actionCommand, ButtonGroup buttonGroup, boolean selected)
make Radio Button
JRadioButton rb = new JRadioButton(text);
rb.setSelected(selected);
rb.setActionCommand(actionCommand);
buttonGroup.add(rb);
return rb;
JToggleButtonmakeToggleButton(final Object owner, final String id, final String altText, final int wpad, final int hpad)
Constructs a JToggleButton with an icon from the given file id.
final URL url = owner.getClass().getResource(id);
ImageIcon icon = null;
if (url != null)
    icon = new ImageIcon(url);
JToggleButton button;
if (icon == null)
    button = new JToggleButton(altText);
else {
...
JButtonnewButton(String name, String text)
new Button
JButton button = new JButton(text);
button.setName(name);
return button;
ComponentnewButton(String text, ActionListener... listeners)
new Button
return newButton(text, null, listeners);
JPopupMenunewButtonPopup(final JToggleButton button)
new Button Popup
final JPopupMenu popup = new JPopupMenu();
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ev) {
        if (button.isSelected()) {
            popup.show(button, 0, button.getHeight());
        } else {
            popup.setVisible(false);
});
popup.addPopupMenuListener(new PopupMenuListener() {
    public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        button.setSelected(false);
        button.setEnabled(false);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                button.setEnabled(true);
        });
    public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
    public void popupMenuCanceled(PopupMenuEvent ev) {
});
return popup;
CollectionnewButtonsFrom(Collection action)
new Buttons From
Collection<JButton> buttons = new ArrayList<JButton>();
for (AbstractAction a : action) {
    buttons.add(new JButton(a));
return buttons;
JButtonnewJButton()
new J Button
final JButton[] jButton = new JButton[1];
try {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            jButton[0] = new JButton();
    });
...