tags:

views:

471

answers:

2

I am trying to undecorate a JInternalFrame, i.e. remove the default titlebar using the following code;

BasicInternalFrameUI ui = (BasicInternalFrameUI)internalFrame.getUI();
ui.getNorthPane().setPrefrredSize(new Dimension(0,0));

I works on windows but the second line throws a NullPointerException on MacOS

Any ideas why and how to get round it?

A: 

I don't use a Mac so I don't know what is causing the problem.

A JInternalFrame without the title bar loses its ability to be dragged. You should be able to accomplish the same goal by just adding a JPanel to the desktop. You would need to set the bounds of the panel. You might also want to use one of the internal frame custom borders on the panel:

UIManager.getBorder("InternalFrame.paletteBorder");
UIManager.getBorder("InternalFrame.optionDialogBorder");

Or maybe another option is to use:

internalFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);

This will replace the title bar with a small palette that can be used to drag the internal frame without the buttons or title.

camickr
"A JInternalFrame without the title bar loses its ability to be dragged" -- but it still can be resized ;)
ivan_ivanovich_ivanoff
@ivan I have custom code to handle the resizing and window dragging.
n002213f
A: 

On Mac, the JInternalFrame doesn't have a north pane. Only execute the code on none Mac OS platforms;

// only remove the northpanel for none Mac OS
if(!(System.getProperty("os.name").startsWith("Mac OS"))){
    BasicInternalFrameUI ui = (BasicInternalFrameUI) getUI();
    ui.getNorthPane().setPrefrredSize(new Dimension(0,0));
}

So much about cross platform :-(

n002213f