如何从JDialog中完全删除图标?(How to completely remove an icon from JDialog?)
我正在创建一个对话框,用于显示文件复制的进度。 我想要做的是完全删除对话框的图标图像。
在提供应用程序的FrameView实例作为JDialog的构造函数的参数之前,我创建了这样的对话框,如下所示:
public class MyAppView extends FrameView { // ... @Action public void showOptiDialog() { // Creating modal opti' dialog JDialog optiDialog = new JDialog(this, true); // ... } }所以,正如我所看到的,我需要一个父组件来使我的对话框没有图标。 在我目前的情况下(当我没有父框架视图时)我尝试了以下hack方法设置一个透明图标,但它不能像我期望的那样工作 - 我仍然看到对话框标题栏中的图标的空白区域和(这是什么最糟糕的)当我点击这个区域时,我仍然有一个弹出窗口。
JFrame dummyFrame = new JFrame(); Image icon = new BufferedImage(1, 1, BufferedImage.TYPE_IT_ARGB_PRE); dummyFrame.setIconImage(icon); JDialog myDialog = new JDialog(dummyFrame, true);无论如何,必须可以删除图标。 工作示例是JOptionPane :
JOptionPane.showMessage(null, "My message");查看JOptionPane的源代码,可以发现当父组件设置为null时,静态Frame JOptionPane.getRootFrame()用于获取调用的父级:
public static Frame getRootFrame() throws HeadlessException { Frame sharedFrame = (Frame)SwingUtilities.appContextGet(sharedFrameKey); if (sharedFrame == null) { sharedFrame = SwingUtilities.getSharedOwnerFrame(); SwingUtilities.appContextPut(sharedFrameKey, sharedFrame); } return sharedFrame; }所以我也尝试按如下方式创建对话框:
JDialog myDialog = new JDialog(JOptionPane.getRootFrame(), true);但仍然没有成功。 当我尝试应用此代码片段时,我有一个标准的Java图标。
我的问题是:我做错了什么? 如何通过JOptionPane完全删除JDialog的图标?
PS我使用JDK6。
I am creating a dialog for showing a progress of files' copying. What I want to do is to completely remove dialog's icon image.
I created such kind of dialogs before providing an application's instance of FrameView as an argument for JDialog's ctructor like this:
public class MyAppView extends FrameView { // ... @Action public void showOptiDialog() { // Creating modal opti' dialog JDialog optiDialog = new JDialog(this, true); // ... } }So, as I can see, I need a parent component to make my dialog with no icon. In my current case (when I have no parent frame view) I tried the following hack method setting a transparent icon but it doesn't work as I expect - I still see an empty area for an icon in dialog's title bar and (what's the worst) I still have a popup window when I click this area.
JFrame dummyFrame = new JFrame(); Image icon = new BufferedImage(1, 1, BufferedImage.TYPE_IT_ARGB_PRE); dummyFrame.setIconImage(icon); JDialog myDialog = new JDialog(dummyFrame, true);Anyway, it must be possible to remove an icon. The working example is JOptionPane:
JOptionPane.showMessage(null, "My message");Looking at JOptionPane's source code one can find that static Frame JOptionPane.getRootFrame() is used to get a parent for the calls when parent component is set to null:
public static Frame getRootFrame() throws HeadlessException { Frame sharedFrame = (Frame)SwingUtilities.appContextGet(sharedFrameKey); if (sharedFrame == null) { sharedFrame = SwingUtilities.getSharedOwnerFrame(); SwingUtilities.appContextPut(sharedFrameKey, sharedFrame); } return sharedFrame; }So I've also tried to create my dialog as follows:
JDialog myDialog = new JDialog(JOptionPane.getRootFrame(), true);but there is still no success. I have a standard Java icon when I try to apply this code snippet.
And my question is: what am I doing wrong? How to completely remove an icon of JDialog as it is done by JOptionPane?
P.S. I use JDK6.
最满意答案
也许以下更符合你想要的方向。
JProgressBar pb = new JProgressBar(); JOptionPane op = new JOptionPane(pb, JOptionPane.PLAI_MESSAGE, JOptionPane.DEFAULT_OPTIO); JDialog dlg = (, "Progress"); dlg.setVisible(true);The solution is to make a dialog non-resizable and then it will be without an icon with any parent window.
JDialog myDialog = new JDialog(new Frame(), true); myDialog.setResizable(false); myDialog.setVisible(true);Unfortunately, if your dialog is to be resizable there is no way to remove an icon except of setting a transparent icon.
#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
推荐阅读
留言与评论(共有 13 条评论) |
本站网友 糙米粥 | 14分钟前 发表 |
true); // ... } } So | |
本站网友 bosch中国 | 23分钟前 发表 |
JProgressBar pb = new JProgressBar(); JOptionPane op = new JOptionPane(pb | |
本站网友 警校招生 | 26分钟前 发表 |
JFrame dummyFrame = new JFrame(); Image icon = new BufferedImage(1 | |
本站网友 飞梭 | 0秒前 发表 |
如下所示: public class MyAppView extends FrameView { // ... @Action public void showOptiDialog() { // Creating modal opti' dialog JDialog optiDialog = new JDialog(this | |
本站网友 什么杀毒软件比较好 | 1分钟前 发表 |
BufferedImage.TYPE_IT_ARGB_PRE); dummyFrame.setIconImage(icon); JDialog myDialog = new JDialog(dummyFrame | |
本站网友 赤字增加的时期是 | 15分钟前 发表 |
I am creating a dialog for showing a progress of files' copying. What I want to do is to completely remove dialog's icon image. I created such kind of dialogs before providing an application's instance of FrameView as an argument for JDialog's ctructor like this | |
本站网友 玫瑰花园 | 23分钟前 发表 |
true); but there is still no success. I have a standard Java icon when I try to apply this code snippet. And my question is | |
本站网友 bt中国 | 15分钟前 发表 |
我有一个标准的Java图标 | |
本站网友 洗黑钱下载 | 26分钟前 发表 |
sharedFrame); } return sharedFrame; } So I've also tried to create my dialog as follows | |
本站网友 大葱的作用 | 13分钟前 发表 |
"Progress"); dlg.setVisible(true); The solution is to make a dialog non-resizable and then it will be without an icon with any parent window. JDialog myDialog = new JDialog(new Frame() | |
本站网友 济南癫痫医院 | 28分钟前 发表 |
JDialog myDialog = new JDialog(JOptionPane.getRootFrame() | |
本站网友 荣城二手房 | 16分钟前 发表 |
我想要做的是完全删除对话框的图标图像 |