aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Focus problem using JOptionPane.showInternalMessageDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus problem using JOptionPane.showInternalMessageDialog" Watch "Focus problem using JOptionPane.showInternalMessageDialog" New topic
Author

Focus problem using JOptionPane.showInternalMessageDialog

Hitesh P Patel
Greenhorn

Joined: May 23, 2012
Posts: 8
I have JFrame, which contain JInternalFrame. JInternalFrame contains 3 labels, 3 textfield and 2 buton.
When user after entering details in textfield click OK, if any of the textfield is left blank a message is displayed and focus should return to that textfield.
When JOptionPane.showMessageDialog is used it works perfect, it display message and focus return to empty textfield.
The problem is when using JOptionPane.showInternalMessageDialog it display message and focus remain on OK button.

Please help and let me know what i am missing in the code.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if it works fine for one, but not the other, why waste your time on 'the other'?
Hitesh P Patel
Greenhorn

Joined: May 23, 2012
Posts: 8
Yes it true, but there is two thing.
First : look of message dialog using showMessageDialog and showInternalMessageDialog is different.
Second : I want to know why its not working. I tried but cant figure out the problem, so i posted the same here to get help.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
1) looks like showInternalMessageDialog inherits the L & F of its parent.
it needs a parent (try null as parent) whereas the showMessageDialog doesn't.

2) you'd need to dig into the source codes of both to see what's different.
simple fix is to add the earlier line
Message = ValidateForm();
after the optionPane. having it the second time will only handle the focus request.
Hitesh P Patel
Greenhorn

Joined: May 23, 2012
Posts: 8
1) looks like showInternalMessageDialog inherits the L & F of its parent.
it needs a parent (try null as parent) whereas the showMessageDialog doesn't.


It show Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent

2) you'd need to dig into the source codes of both to see what's different.
simple fix is to add the earlier line
Message = ValidateForm();
after the optionPane. having it the second time will only handle the focus request.


It works that ways and already tried before posting code for help.
It will not be good programming to call the routine twice for focus, but for temporary solution i will go with it until I find any solution.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
here's another way, moving the focus request

Hitesh P Patel
Greenhorn

Joined: May 23, 2012
Posts: 8
Its better solution then calling the routine twice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Focus problem using JOptionPane.showInternalMessageDialog