Java JButton Settings removeCloseButton(Component comp)

Here you can find the source of removeCloseButton(Component comp)

Description

Only works for default look and feel, where Swing creates a real close button.

License

Open Source License

Declaration

public static void removeCloseButton(Component comp) 

Method Source Code


//package com.java2s;
/*//from ww  w . j  a va 2  s. co  m
* Argus Open Source
* Software to apply Statistical Disclosure Control techniques
* 
* Copyright 2014 Statistics Netherlands
* 
* This program is free software; you can redistribute it and/or 
* modify it under the terms of the European Union Public Licence 
* (EUPL) version 1.1, as published by the European Commission.
* 
* You can find the text of the EUPL v1.1 on
* https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
* 
* This software is distributed on an "AS IS" basis without 
* warranties or conditions of any kind, either express or implied.
*/

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

import javax.swing.AbstractButton;
import javax.swing.Action;

import javax.swing.JMenu;

public class Main {
    /**
     * Only works for default look and feel, where Swing creates a real close
     * button. In other look and feels close buttons are handled by the native
     * OS and are not part of the Swing component hierarchy.
     */
    public static void removeCloseButton(Component comp) {
        if (comp instanceof JMenu) {
            Component[] children = ((JMenu) comp).getMenuComponents();
            for (int i = 0; i < children.length; ++i) {
                removeCloseButton(children[i]);
            }
        } else if (comp instanceof AbstractButton) {
            Action action = ((AbstractButton) comp).getAction();
            String cmd = (action == null) ? "" : action.toString();
            if (cmd.contains("CloseAction")) {
                comp.getParent().remove(comp);
            }
        } else if (comp instanceof Container) {
            Component[] children = ((Container) comp).getComponents();
            for (int i = 0; i < children.length; ++i) {
                removeCloseButton(children[i]);
            }
        }
    }
}

Related

  1. opacityCheck(AbstractButton b)
  2. paintClassicText(AbstractButton b, Graphics g, int x, int y, String text, int mnemIndex)
  3. parseLevel(ButtonGroup buttonGroup)
  4. removeAllActionListeners(AbstractButton btn)
  5. removeButtonBorder(AbstractButton button)
  6. removeListeners(AbstractButton button)
  7. scaleAllAbstractButtonIconsOf(Container container, int size)
  8. scaleButtonIcon(Icon icon, int size)
  9. ScaleButtonIcon(JToggleButton btn, int width, int height, int fontsize)