简体   繁体   中英

Remove maximize, minimize, close button from JPanel

In JDesktopPane, i have included a JPanel with tree view listing some devices. I dont need those resizable and close options in that panel show in the figure. (Maximize, Minimize, Close). I tried many ways, but not able to hide those functions. Any ideas.

在此输入图像描述

The component you actually need to be dealing with is the JInternalFrame which contains the JPanel you mentioned above. This should have a number of functions to enable/disable the actions associated with the min/max/close buttons (Eg: setMaximizable(bool enabled) ).

I do not know if this would hide the buttons or merely disable them, so you may have to use some variant of the trick mentioned by RJ - manually removing the buttons.

setMaximizable(false), 
setMinimizabel(false), 
setClosable(false)

You can remove the minimize, maximize and close buttons from a swing component like this:-

public void removeMinMaxClose(Component comp) {
    if (comp instanceof AbstractButton) {
        comp.getParent().remove(comp);
    }
    if (comp instanceof Container) {
        Component[] comps = ((Container) comp).getComponents();
        for (int x = 0, y = comps.length; x < y; x++) {
            removeMinMaxClose(comps[x]);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM