开发者

Why does the Java AWT FileDialog setIconImage method fail to set the icon?

开发者 https://www.devze.com 2022-12-12 02:37 出处:网络
I am attempting to use a J开发者_StackOverflowava AWT FileDialog, but I want to replace the default Java Dialog icon with something else.In short, the code looks something like this:

I am attempting to use a J开发者_StackOverflowava AWT FileDialog, but I want to replace the default Java Dialog icon with something else. In short, the code looks something like this:

Frame frame = new Frame();
Image image = ImageIO.read(new URL("file:/path/to/myfile.jpg"));
FileDialog fileDialog = new FileDialog(frame, "Save As", FileDialog.SAVE);

fileDialog.setIconImage(image);
fileDialog.setDirectory("/path/to/directory");
fileDialog.setFile("filename.txt");

fileDialog.setVisible(true);

I've tried several variation, including a different method of reading the image, packing the FileDialog, packing the Frame, setting the icon of the Frame, etc. However, regardless of what I try, the FileDialog icon never changes. When I set the icon of the Frame and set the Frame to visible, the frame displayed the correct icon, but it was still a no go for the FileDialog.

Any Thoughts?


FileDialog, being an AWT component, is going to be more tied to the local platform. In the Solaris case, it's possible it's picking up the icon from the java executeable that launched your app itself.

Is there a reason you can't use JFileChooser?


That might not be possible on all platforms. I guess the FileDialog somehow uses the filedialog provided by the OS and if that doesn't support icons you are out of luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消