Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem - JDialog versus L&F

 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Camick
Ranch Hand
Posts: 2559
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()!).
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 2559
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic