如何移除Java Swing中JDialog窗口左上角的Red Hat图标
移除JDialog窗口左上角RHEL Red Hat图标方法
这个图标是RHEL系统下Java Swing采用GTK风格Look and Feel(LaF)时,系统窗口装饰自动添加的。以下是几种可行的解决方式:
方法一:自定义窗口装饰
关闭系统默认装饰,自行绘制仅含“Activities”文本的标题栏:JDialog dialog = new JDialog(); dialog.setUndecorated(true); // 禁用系统窗口装饰 // 构建自定义标题面板 JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); titlePanel.add(new JLabel("Activities")); // 组装对话框布局 dialog.setLayout(new BorderLayout()); dialog.add(titlePanel, BorderLayout.NORTH); dialog.add(new JLabel("对话框内容"), BorderLayout.CENTER); // 添加业务组件 dialog.pack(); dialog.setVisible(true);注意:此方式需要自行实现窗口拖动、关闭等基础功能(若有需求)。
方法二:修改GTK全局配置
通过修改GTK配置隐藏所有GTK风格窗口的图标,在用户主目录下的~/.gtkrc-2.0文件中添加:style "no-window-icon" { GtkWindow::icon-name = "" } class "GtkWindow" style "no-window-icon"注意:该配置会影响所有使用GTK风格的Java Swing应用,并非仅针对目标JDialog。
方法三:设置空图标覆盖系统图标
直接给JDialog设置一个透明空图标,尝试覆盖系统默认图标:JDialog dialog = new JDialog(); dialog.setIconImage(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)); dialog.setTitle("Activities"); dialog.pack(); dialog.setVisible(true);此方式在部分LaF环境下生效,Swing会优先使用自定义设置的图标。
内容的提问来源于stack exchange,提问作者James
相关产品推荐
相关产品推荐

