隐藏 JInternalFrame 的标题栏?-java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7218608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:08:50  来源:igfitidea点击:

hiding title bar of JInternalFrame? -java

javaswinguser-interfacejframejinternalframe

提问by Tushar Chutani

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

我在网上找到了一些代码,我编辑了一下。我想隐藏 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.

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

回答by user2050146

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.

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

回答by Mark Ainsworth

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

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

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

in your case I think

在你的情况下,我认为

回答by enam

for me this works very well:

对我来说,这很有效:

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

thanks.

谢谢。

回答by jerba

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 JInternalFramelike this:

别人怎么说。根据框架,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
           }
        };