如何删除JFrame中的标题栏 [英] How to remove title bar in JFrame

查看:148
本文介绍了如何删除JFrame中的标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码进行练习,

I'm using the following code for practising,

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

我还添加

frame.setSize(frame.getMaximumSize());

在createAndShowGUI()方法中,

in createAndShowGUI() method,

更有甚者,我希望这个窗口没有标题栏,关闭和最小化按钮。

What is more I want this window not to have the title bar, close and minimize buttons.

我尝试了以下代码,

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

如果我在pack()之前添加了这段代码,它将进入infine循环,此异常线程AWT-EventQueue-0中的异常java.lang.NegativeArraySizeException

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

如果我添加了createAndShowGUI()方法的最后一行,则抛出线程AWT-EventQueue-0中的异常java.awt.IllegalComponentStateException:框架可显示。

If I added the last line of createAndShowGUI() method it throws Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable.

我该怎么办?

谢谢。

推荐答案

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

这篇关于如何删除JFrame中的标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆