如何使用jFrame上的关闭按钮创建自定义标题栏? [英] How to create customize title bar with close button on jFrame?
本文介绍了如何使用jFrame上的关闭按钮创建自定义标题栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的JFrame
创建一个自定义的标题栏.我可以通过以下方式删除默认标题栏:
I want to create a customised title bar for my JFrame
. I can remove the default title bar with
JFrame.setUndecorated(true)
现在我需要使用关闭按钮为JFrame
创建自定义标题栏吗?
Now i need to create a customised title bar for my JFrame
with a close button?
推荐答案
我从来没有做过这样的事情,
Without having done that ever, I think I would go this way:
- 确实将
JFrame
设置为未装饰 - 扩展
JRootPane
以添加其他字段titleBar
- 创建一个包含标题,关闭按钮等的
TitleBar
组件... - 在该
JRootPane
上设置一个新的LayoutManager
(看一下JRootPane.RootLayout
)并按照适当的顺序排列组件(首先是标题栏,然后是菜单栏,然后是内容窗格) - 在您的
JFrame
上设置扩展
RootPane
的实例
- Indeed set the
JFrame
to undecorated - Extend
JRootPane
to add an additional fieldtitleBar
- Create a
TitleBar
component holding the title, the close button, etc... - Set a new
LayoutManager
on thatJRootPane
(have a look atJRootPane.RootLayout
) and layout the components in the appropriate order (first the title bar, then below the menubar, then below the content pane) - Set an instance of that extends
RootPane
on yourJFrame
也许有更好的方法.
这篇关于如何使用jFrame上的关闭按钮创建自定义标题栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文