如何使用jFrame上的关闭按钮创建自定义标题栏? [英] How to create customize title bar with close button on jFrame?

查看:75
本文介绍了如何使用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:

  1. 确实将JFrame设置为未装饰
  2. 扩展JRootPane以添加其他字段titleBar
  3. 创建一个包含标题,关闭按钮等的TitleBar组件...
  4. 在该JRootPane上设置一个新的LayoutManager(看一下JRootPane.RootLayout)并按照适当的顺序排列组件(首先是标题栏,然后是菜单栏,然后​​是内容窗格)
  5. 在您的JFrame
  6. 上设置扩展RootPane的实例
  1. Indeed set the JFrame to undecorated
  2. Extend JRootPane to add an additional field titleBar
  3. Create a TitleBar component holding the title, the close button, etc...
  4. Set a new LayoutManager on that JRootPane (have a look at JRootPane.RootLayout) and layout the components in the appropriate order (first the title bar, then below the menubar, then below the content pane)
  5. Set an instance of that extends RootPane on your JFrame

也许有更好的方法.

这篇关于如何使用jFrame上的关闭按钮创建自定义标题栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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