aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JDialog With Icon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialog With Icon" Watch "JDialog With Icon" New topic
Author

JDialog With Icon

NILESH PATEL
Ranch Hand

Joined: Nov 21, 2000
Posts: 71
Dear all,
I have just created a Modal JDialog. When I run the program I see default program icon on the top-left hand corner.(Little icon). For example on Linux-KDE I see "K" as an icon. This works fine with JFrames using setImageIcon(...) method.
Question is how can we do that for JDialog if at all possible. or do we have to live with system default icon.
Please help.
Thanks in advance.
Nilesh
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
It will use whatever the parent frame uses for an icon. JFileChooser works the same way.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
if you need just basic dialogs, use JOptionPane.show######Dialog(). there are methods where you can specify the icon.If you need more complex dialogs, try the JOptionPane methods as well. you can trick a bit as the message is of type object, not String. this way I've been inserting combo boxes, for example.
chantal
NILESH PATEL
Ranch Hand

Joined: Nov 21, 2000
Posts: 71
Thanks for your replies. But I have created a frame, say a wizrd box with about six tabbed pannes. Until now that frame was activated and worked with independantly. However due to overheads on the software I decided to make it modal, so user has to dispose one frame after finishing. This is where I get a problem. Using option pane you can create dialog and icons, but you are only limited to icons within content pane, but not next to string title of dialog/frame.
Is it correct? I think it is. But please comment on this and thanks again.
Nilesh
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
sorry, I missed that point entirely in your posting.
Seems to me like you will have to extend JDialog to get the Icon into the frameborder.
chantal
NILESH PATEL
Ranch Hand

Joined: Nov 21, 2000
Posts: 71
Thanks,
I can do that, no problem with extending, but problem stays with JDialog itself. If we look at API of JDialog, it does not support IconImage methods, only frames and other components.
So extension of JDialog would not help, I Think....
However for timebeing what I have done is, I have passed a parent frame with icon to the current frame(to be modaled), Then setting contentpane of this dialog to be contentpane of the current frame. I think following should make this understand better.
1) Created a parent frame-A with some menus and buttons and so on, setting IconImage as well.
2) Created a JDialog with "new JDialog(frame-A);
3) Created another frame-B with tabbed panes, to be modaled.
4) Introduced a method called "void Display(JDialog)
5) Called this method from frame-A.
6) Replaced Contentpane of Dialog in Display() method, with contentpane of frame-B, usinf JDialog.setContentPane(...) method.
7) pack() and show() dialogs.
This really worked and also provided flexibility of using JFrame features in modal Dialog/Frame.
I think this is got to be the way round unles you guys can suggest better option. At least this works great.
Thanks again all, keep posting.
Nilesh
 
 
subject: JDialog With Icon