如何从JDialog中完全删除图标? [英] How to completely remove an icon from JDialog?
问题描述
我正在创建一个对话框,用于显示文件复制的进度。我想要做的是完全删除对话框的图标图像。
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.
我在提供应用程序的实例 FrameView $之前创建了这种对话框c $ c>作为
JDialog
的构造函数的参数:
I created such kind of dialogs before providing an application's instance of FrameView
as an argument for JDialog
's constructor like this:
public class MyAppView extends FrameView {
// ...
@Action
public void showOptionsDialog() {
// Creating modal options' dialog
JDialog optionsDialog = new JDialog(this, true);
// ...
}
}
所以,正如我所看到的,我需要一个父组件来使我的对话框没有图标。在我目前的情况下(当我没有父框架视图时)我尝试了以下hack方法设置一个透明图标,但它不能像我期望的那样工作 - 我仍然看到对话框标题栏中的图标的空白区域(是什么当我点击这个区域时,我仍然有一个弹出窗口。
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_INT_ARGB_PRE);
dummyFrame.setIconImage(icon);
JDialog myDialog = new JDialog(dummyFrame, true);
无论如何,必须可以删除图标。工作示例是 JOptionPane :
Anyway, it must be possible to remove an icon. The working example is JOptionPane:
JOptionPane.showMessage(null, "My message");
查看 JOptionPane
的源代码一可以找到静态 Frame JOptionPane.getRootFrame()
用于在父组件设置为 null $ c $时获取调用的父级c>:
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);
但仍然没有成功。当我尝试应用此代码段时,我有一个标准的Java图标。
but there is still no success. I have a standard Java icon when I try to apply this code snippet.
我的问题是:我做错了什么? 如何通过 JOptionPane
?
And my question is: what am I doing wrong? How to completely remove an icon of JDialog
as it is done by JOptionPane
?
PS我使用JDK6。
P.S. I use JDK6.
推荐答案
解决方案是使对话框不可调整大小,然后它将没有任何父级的图标窗口。
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.
这篇关于如何从JDialog中完全删除图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!