JFrame 上关闭/最小化按钮的自定义设计

编程入门 行业动态 更新时间:2024-10-11 19:25:45
本文介绍了JFrame 上关闭/最小化按钮的自定义设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想应用我自己的关闭和最小化按钮.有没有办法改变 JFrame 的设计?

I would like to apply my own close and minimize buttons. Is there any way to change the JFrame design?

推荐答案

诀窍在于 PLAF 和 setDefaultLookAndFeelDecorated(true) (指定窗口装饰).

例如

import java.awt.BorderLayout; import javax.swing.*; public class FrameCloseButtonsByLookAndFeel { FrameCloseButtonsByLookAndFeel() { String[] names = { UIManager.getSystemLookAndFeelClassName(), UIManager.getCrossPlatformLookAndFeelClassName() }; for (String name : names) { try { UIManager.setLookAndFeel(name); } catch (Exception e) { e.printStackTrace(); } // very important to get the window decorations. JFrame.setDefaultLookAndFeelDecorated(true); JFrame f = new JFrame(UIManager.getLookAndFeel().getName()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel gui = new JPanel(new BorderLayout()); f.setContentPane(gui); JTree tree = new JTree(); tree.setVisibleRowCount(4); gui.add(tree, BorderLayout.LINE_START); gui.add(new JScrollPane(new JTextArea(3,15))); JToolBar toolbar = new JToolBar(); gui.add(toolbar, BorderLayout.PAGE_START); for (int ii=1; ii<5; ii++) { toolbar.add(new JButton("Button " + ii)); if (ii%2==0) { toolbar.addSeparator(); } } f.pack(); f.setLocationByPlatform(true); f.setVisible(true); } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new FrameCloseButtonsByLookAndFeel(); } }); } }

更多推荐

JFrame 上关闭/最小化按钮的自定义设计

本文发布于:2023-07-18 15:48:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1146380.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最小化   自定义   按钮   JFrame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!