Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Problem - JDialog versus L&F  RSS feed

 
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.
 
Rancher
Posts: 3042
22
  • 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!
 
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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
Rancher
Posts: 3042
22
  • 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 :-)
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!