如何在JFrame TitleBar中添加任何组件 [英] How to add any Component in the JFrame TitleBar

查看:109
本文介绍了如何在JFrame TitleBar中添加任何组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Java swing中的JFrame TitleBar上添加任何组件(如JButton).

How to add any Component like a JButton on the JFrame TitleBar in java swing.

推荐答案

我认为通过标题栏"您会想到带有窗口菜单按钮,文档或程序标题以及(典型)最大化,最小化,关闭按钮的标题

I assume by "title bar" you think of the header with the window menu button, document or program title and buttons for (typical) maximize, minimize, close.

窗口边框是由操作系统绘制的(通常,无论是哪个部分,例如,对于XServer,大多数情况下它都是窗口管理器).这就是用户想要的-通常.然后,窗口的这一部分不在Swing的支持范围内,您需要通过本机代码(JNI或其更好的包装器之一,如JNA)添加组件.

The window borders are drawn by the operating system (whatever part, e.g. with XServer it would be a window manager most of the time) - usually. And this is what the user wants - usually. Then this part of the window is outside the reach of Swing, you need to add components by native code (JNI or one of its nicer wrappers like JNA).

但是您可以通过setUndecoratedFrame设置为未修饰.这将整个窗口区域留在您的责任范围内,您必须自己绘制所有内容并注意诸如窗口的可拖动性之类的事情.考虑一个完全剥皮"的应用程序.如果您使用的外观支持绘制Windows边框(javax.swing.LookAndFeel#getSupportsWindowDecorations()),而不必自己设置,而是设置JFrame.setDefaultLookAndFeelDecorated(),则LookAndFeel将使用Swing组件绘制边框.然后,您可以通过玻璃窗格或通过更改绘制标题栏的组件来添加Swing组件.

But you can set a Frame to undecorated via setUndecorated. This leaves the whole window area in your responsibility, you have to draw everything yourself and care for things like draggability of the window. Think of a completely "skinned" application. If the look and feel you use supports drawing of the windows borders (javax.swing.LookAndFeel#getSupportsWindowDecorations()) you don't have to do this yourself but set JFrame.setDefaultLookAndFeelDecorated(), the LookAndFeel will draw the border with Swing components. Then you can add Swing components either by glasspane or by changing the component that draws the title bar.

这篇关于如何在JFrame TitleBar中添加任何组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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