• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focus problem using JOptionPane.showInternalMessageDialog

 
Hitesh P Patel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it works fine for one, but not the other, why waste your time on 'the other'?
 
Hitesh P Patel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's another way, moving the focus request

 
Hitesh P Patel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its better solution then calling the routine twice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic