Java Utililty Methods JButton Settings

List of utility methods to do JButton Settings

Description

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

Method

booleanhasText(AbstractButton button)
Checks whether the specified button has associated text.
String text = button.getText();
if ((text != null) && (text.length() > 0)) {
    return true;
return false;
voidhideApproveButton(JFileChooser fileChooser)
hide Approve Button
fileChooser.setApproveButtonText("approveButton");
JButton button = lookupButton(fileChooser, "approveButton");
fileChooser.setApproveButtonText(null);
button.setVisible(false);
voidhideJFileChooserButtons(JFileChooser sessionFileChooser)
hide J File Chooser Buttons
hideChildButtonsWithTooltip(sessionFileChooser, "Sessions at server");
hideChildButtonsWithTooltip(sessionFileChooser, "Up One Level");
hideChildButtonsWithTooltip(sessionFileChooser, "Remote sessions");
hideChildButtonsWithTooltip(sessionFileChooser, "Create New Folder");
hideChildButtonsWithTooltip(sessionFileChooser, "List");
hideChildButtonsWithTooltip(sessionFileChooser, "Details");
ComponentinterButtonSpace()
A horizontal strut between buttons on the same line.
return Box.createHorizontalStrut(STANDARD_SPACE);
booleanisScrollBarButton(AbstractButton button)
Checks and answers if the specified button is in a scroll bar.
Container parent = button.getParent();
return (parent != null) && ((parent instanceof JScrollBar) || (parent.getParent() instanceof JScrollBar));
booleanisSelected(AbstractButton... buttons)
is Selected
for (AbstractButton button : buttons) {
    if (button.isSelected()) {
        return true;
return false;
booleanisSelected(final AbstractButton abstractButton)
is Selected
if (abstractButton != null) {
    if (SwingUtilities.isEventDispatchThread()) {
        return abstractButton.isSelected();
    } else {
        final boolean[] isSelected = new boolean[1];
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
...
booleanisSelected(final AbstractButton abstractButton)
is Selected
return abstractButton != null
        && runInEDT(() -> Boolean.valueOf(abstractButton.isSelected())).booleanValue();
JButtonlookupButton(Container c, String text)
Find button by text
JButton button = null;
for (Component comp : c.getComponents()) {
    if (comp == null) {
        continue;
    if (comp instanceof JButton && (button = (JButton) comp).getText() != null
            && button.getText().equals(text)) {
        return button;
...
JButtonnewTabbedPaneButton(String text)
Returns a button to add to a panel in a tabbed pane.
JButton button = new JButton(text);
if (getUseNonOpaqueTabbedPaneComponents())
    button.setOpaque(false);
return button;