• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Focus problem using JOptionPane.showInternalMessageDialog

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its better solution then calling the routine twice.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic