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?

Lukas Rotter
  • 4,158
  • 1
  • 15
  • 35
n002213f
  • 7,805
  • 13
  • 69
  • 105

2 Answers2

1

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
  • 7,805
  • 13
  • 69
  • 105
0

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
  • 321,443
  • 19
  • 166
  • 288