Java JButton Settings hideApproveButton(JFileChooser fileChooser)

Here you can find the source of hideApproveButton(JFileChooser fileChooser)

Description

hide Approve Button

License

Open Source License

Declaration

public static void hideApproveButton(JFileChooser fileChooser) 

Method Source Code


//package com.java2s;
//License from project: GNU General Public License 

import java.awt.Component;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFileChooser;

public class Main {
    public static void hideApproveButton(JFileChooser fileChooser) {
        // this will initialize the button and its parent component
        fileChooser.setApproveButtonText("approveButton");
        JButton button = lookupButton(fileChooser, "approveButton");
        // reset approve button text
        fileChooser.setApproveButtonText(null);
        // hide it
        button.setVisible(false);//from  w  w  w  .ja  va2 s. com
    }

    /**
     * Find button by text
     * 
     * @param c
     * @param text
     * @return
     */
    private static JButton lookupButton(Container c, String 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;
            } else if (comp instanceof Container) {
                if ((button = lookupButton((Container) comp, text)) != null) {
                    return button;
                }
            }
        }
        return button;
    }
}

Related

  1. groupButtons(AbstractButton... buttons)
  2. groupButtons(final Container container, final boolean recursive)
  3. growFont(JComponent button)
  4. hasIcon(AbstractButton button)
  5. hasText(AbstractButton button)
  6. hideJFileChooserButtons(JFileChooser sessionFileChooser)
  7. interButtonSpace()
  8. isScrollBarButton(AbstractButton button)
  9. isSelected(AbstractButton... buttons)