10

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

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

4

4 回答 4

16

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

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

在你的情况下,我认为

于 2014-04-05T23:01:09.840 回答
14

首先将内部框架转换为基本内部框架。

像这样做:-

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

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

于 2013-06-03T07:11:54.137 回答
1

别人怎么说。根据框架,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
           }
        };
于 2018-07-09T21:05:33.457 回答
0

对我来说这很好用:

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

谢谢。

于 2016-06-12T01:05:22.243 回答