10

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.

Fjondor
  • 39
  • 7
Tushar Chutani
  • 1,522
  • 5
  • 27
  • 57

4 Answers4

16

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

Mark Ainsworth
  • 811
  • 8
  • 24
  • Nice, this is the correct answer, unlike .setUI(null)! I also read somewhere that you might need to do this again after certain events (like minimizing the window) – Dmitry Avtonomov May 27 '14 at 20:45
  • This is the correct answer. It is also useful when combined with `frame.setBorder(null);` to use a [`JInternalFrame`](https://docs.oracle.com/javase/8/docs/api/javax/swing/JInternalFrame.html) as a solo component within a top-level [`JFrame`](http://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html) as if it were a [`JPanel`](http://docs.oracle.com/javase/8/docs/api/javax/swing/JPanel.html). – Parker Jun 24 '15 at 20:15
  • Worked for me. I wasn't even going to try, but works like charm. Thank you. – George Oct 01 '15 at 14:39
15

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.

balsick
  • 1,099
  • 1
  • 10
  • 23
user2050146
  • 189
  • 2
  • 11
2

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
           }
        };
jerba
  • 21
  • 1
0

for me this works very well:

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

thanks.

enam
  • 952
  • 11
  • 11