aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem - JDialog versus L&F Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem - JDialog versus L&F" Watch "Problem - JDialog versus L&F" New topic
Author

Problem - JDialog versus L&F

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Ranchers!

I've got a problem. I need something more sophisticated than JOptionPane.show*Dialog(), so I've decided to subclass the JDialog.

I was adding some action JButtons (confirm / cancel) but then I realized what the problem is.

When I'll add the JButtons just with add() i will get the exact order of the buttons as inserted. So will end with CONFIRM CANCEL button in that order. However, when I use the System-dependent look and feel, the order of the buttons could be different.

For example, when I create the dialog with JOptionPane.show*Dialog() it always create the buttons adequate to the actual L&F, so in default one I will have
/---------------------\
|                      |
|    CONFIRM CANCEL    |
\---------------------/


while in GDK look and feel I will have

/---------------------\
|                      |
|       CANCEL CONFIRM |
\---------------------/


How can I achieve appropriate L&F rules when using own dialogs?

Cheers!


EDIT: Well, somehow I managed to cope with this problem by adding JOptionPane to my JDialog and listen to property changes which basically solves my problem.


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7
I need something more sophisticated than JOptionPane.show*Dialog(),


You can do some pretty sophisticated stuff with a JOPtionPane since you can add a panel to an option pane. The Dialog Focus link might help you out.
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

I've decided to do something reversed - I've added a JOptionPane to the JDialog and listen to the events (to provide some action before the dialog is closed).

Thanks for help anyway!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Why not use JOptionPane's own dialog? In its Javadoc there is an example titled "Direct Use". You simply call the createDialog method, do some things to that dialog, then call setVisible(true) (not show()!).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

@Rob Prime
Yes, the JOptionPane.createDialog(-) is a solution, but I would like to do some validation before the dialog closes. For example - if data input by the user is not a number, popup an alert and let the user fix it.

Cheers!
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7
but I would like to do some validation before the dialog closes


The section from the Swing tutorial on Stopping Automatic Dialog Closing shows how to do this.
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks Rob, but that's actually what I pointed at the end of the first post:

Pedro Kowalski wrote:EDIT: Well, somehow I managed to cope with this problem by adding JOptionPane to my JDialog and listen to property changes which basically solves my problem.


and what I mean writing this:

Pedro Kowalski wrote:I've decided to do something reversed - I've added a JOptionPane to the JDialog and listen to the events (to provide some action before the dialog is closed).


Thanks anyway mate!

Cheers!

Edit: Oh, and of course the idea was taken from the exact same site you pointed :-)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem - JDialog versus L&F