隐藏JInternalFrame的标题栏? -java

我在网上找到了一些代码,我对它进行了一些编辑。 我想隐藏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); 

问题是标题栏由于某种原因没有被隐藏。 谢谢。

首先将内部框架转换为basicinternalframe。

像这样做:-

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

在此之后,您的标题栏将不可见。

我用这种方式解决了这个问题:我将JInternalFrame子类化并将以下代码添加到其构造函数中。 (我免费获得子类,因为我使用netBeans的GUI Builder)

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

在你的情况下,我认为

对我来说这很有效:

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

谢谢。

别人怎么说。 根据框架,ui可能会更新,这将使它重新出现。 所以对我来说,它可以像这样初始化JInternalFrame

  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 } };