I'd like some help on how to undecorate and decorate back an JInternalFrame. My frame class is this:
package com;
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicInternalFrameUI;
public class InternalFrame extends JInternalFrame
{
private static final long serialVersionUID = -1001515635581955601L;
private Border border;
private final JComponent northPane;
public InternalFrame(String name)
{
super(name, true, true, true, true);
border = getBorder();
northPane = ((BasicInternalFrameUI) getUI()).getNorthPane();
setName(name);
setSize(800, 600);
setLayout(new BorderLayout());
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setFont(new Font("Lucida Console", Font.PLAIN, 12));
}
public void setUndecorated(boolean val)
{
setBorder(val ? null : border);
((BasicInternalFrameUI) getUI()).setNorthPane(val ? null : northPane);
}
}
Then I use:
InternalFrame frame = new InternalFrame("My Internal Frame");
desktop.add(frame);
frame.setVisible(true);
frame.setUndecorated(true);
So far all good, JInternalFrame becomes undecorated as I wanted. Then the problem is when I want to decor the frame again with frame.setUndecorated(false);
Border
will get filled but NorthPane
of the JInternalFrame
will not.
Any suggestions on how to fix that?