简体   繁体   English

如何删除 JFrame 中的标题栏

[英]How to remove title bar in JFrame

I'm using the following code for practising,我正在使用以下代码进行练习,

http://docs.oracle.com/javase/tutorial/uiswing/examples/layout/BorderLayoutDemoProject/src/layout/BorderLayoutDemo.java http://docs.oracle.com/javase/tutorial/uiswing/examples/layout/BorderLayoutDemoProject/src/layout/BorderLayoutDemo.java

I also add我也加

frame.setSize(frame.getMaximumSize());

in createAndShowGUI() method,在 createAndShowGUI() 方法中,

What is more I want this window not to have the title bar, close and minimize buttons.更重要的是我希望这个窗口没有标题栏、关闭和最小化按钮。

I tried the following code,我尝试了以下代码,

frame.setUndecorated(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

If I added this code before the pack(), it goes into infine loop with this exception Exception in thread "AWT-EventQueue-0" java.lang.NegativeArraySizeException如果我在 pack() 之前添加了此代码,它会进入 infine 循环,并在线程“AWT-EventQueue-0”java.lang.NegativeArraySizeException 中出现此异常异常

If I added the last line of createAndShowGUI() method it throws Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable.如果我添加了 createAndShowGUI() 方法的最后一行,它会在线程“AWT-EventQueue-0”中抛出异常 java.awt.IllegalComponentStateException: The frame is displayable。

What should I do ?我该怎么办 ?

Thanks.谢谢。

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Already there
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setUndecorated(true);

Well, the following code snippet in createAndShowGUI() worked for me:好吧, createAndShowGUI()的以下代码片段对我createAndShowGUI()

JFrame frame = new JFrame("BorderLayoutDemo");
frame.setUndecorated(true); // Remove title bar
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addComponentsToPane(frame.getContentPane());
frame.pack();
frame.setVisible(true);

Note that I'm not sure what you're trying to achieve by manually setting the size of an unrealized frame to it's maximum size, which will be (0, 0) initially.请注意,我不确定您要通过手动将未实现帧的大小设置为其最大大小(0, 0)最初为(0, 0)来实现什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM