Tushar Chutani
Tushar Chutani

Reputation: 1560

hiding title bar of JInternalFrame? -java

I found some code online, I edited it a bit. I want to hide title bar of a JInternalFrame.

  JInternalFrame frame = new JInternalFrame();
  // Get the title bar and set it to null
  setRootPaneCheckingEnabled(false);
  javax.swing.plaf.InternalFrameUI ifu= frame.getUI();
  ((javax.swing.plaf.basic.BasicInternalFrameUI)ifu).setNorthPane(null);      

  frame.setLocation(i*50+10, i*50+10);
  frame.setSize(200, 150);
  //frame.setBackground(Color.white);      

  frame.setVisible(true);
  desktop.add(frame);

The problem is that the title bar isn't being hidden for some reason. Thanks.

Upvotes: 10

Views: 19075

Answers (4)

jerba
jerba

Reputation: 21

What the others say. Depending on the framework the ui might get updated though, which will make it reappear. So for me it worked initializing the JInternalFrame like this:

        JInternalFrame internalFrame = new JInternalFrame() {
           @Override
           public void setUI(InternalFrameUI ui) {
               super.setUI(ui); // this gets called internally when updating the ui and makes the northPane reappear
               BasicInternalFrameUI frameUI = (BasicInternalFrameUI) getUI(); // so...
               if (frameUI != null) frameUI.setNorthPane(null); // lets get rid of it
           }
        };

Upvotes: 2

enam
enam

Reputation: 962

for me this works very well:

    putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
    getRootPane().setWindowDecorationStyle(JRootPane.NONE);
    ((BasicInternalFrameUI) this.getUI()).setNorthPane(null);
    this.setBorder(null);

thanks.

Upvotes: 0

user2050146
user2050146

Reputation: 189

First convert the internalframe to basicinternalframe.

do it like this:-

BasicInternalFrameUI bi = (BasicInternalFrameUI)your_internalframe_object.getUI();
bi.setNorthPane(null);

After this your title bar will be invisible.

Upvotes: 15

Mark Ainsworth
Mark Ainsworth

Reputation: 859

I solved this problem this way: I subclass JInternalFrame and add the following code to its constructor. (I get the subclassing for free because I use netBeans' GUI Builder)

((javax.swing.plaf.basic.BasicInternalFrameUI)this.getUI()).setNorthPane(null);

in your case I think

Upvotes: 16

Related Questions