2

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?

Paco Abato
  • 3,920
  • 4
  • 31
  • 54
Charus
  • 41
  • 3

2 Answers2

2

Ok i found a solution here: https://community.oracle.com/thread/1493647. So in my code i add

public void setRootPaneCheckingEnabled(boolean enabled)
{
    super.setRootPaneCheckingEnabled(enabled);
}

and changed my setUndecorated method to:

public void setUndecorated(boolean val)
{
    setBorder(val ? null : border);

    setRootPaneCheckingEnabled(false);
    ((BasicInternalFrameUI) getUI()).setNorthPane(val ? null : northPane);
    setRootPaneCheckingEnabled(true);
}

Now my code is workign perfect.

Charus
  • 41
  • 3
0

As documentation states:

A frame may have its native decorations (i.e. Frame and Titlebar) turned off with setUndecorated. This can only be done while the frame is not displayable.

I guess you are trying to change it while it's displayable:

A component is made displayable either when it is added to a displayable containment hierarchy or when its containment hierarchy is made displayable. A containment hierarchy is made displayable when its ancestor window is either packed or made visible.

A component is made undisplayable either when it is removed from a displayable containment hierarchy or when its containment hierarchy is made undisplayable. A containment hierarchy is made undisplayable when its ancestor window is disposed.

Community
  • 1
  • 1
Paco Abato
  • 3,920
  • 4
  • 31
  • 54