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

有帮助吗?

解决方案

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.

其他提示

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]);
        }
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top