Question

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.

enter image description here

Était-ce utile?

La solution

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 (E.g.: 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 R.J - manually removing the buttons.

Autres conseils

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]);
        }
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top