• 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

showInputDialog( ) focus

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application in which the user drags an object onto a canvas. When the drop occurs the drop target (canvas) executes the statement:
data = JOptionPane.showInputDialog(...). The cursor is blinking in the dialog's text field, but the user has to click on the field (or the dialog window) before input is accepted. Is there a way to automatically set focus for the dialog so the user doesn't have to click it first? I don't see how to use requestFocus() on a modal dialog.
Thanks for our help.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you're mixing AWT and Swing components* here. That may or may not be the cause of your problem, but is better avoided.

I suggest you change your code to use JComponent or JPanel in place of Canvas. You would want to override paintComponent(...) instead of paint(...).

Additionally, if your top-level window is AWT Frame, you would need to change that to JFrame.

*edit Added the word components
[ May 23, 2008: Message edited by: Darryl Burke ]
 
Rob Byrd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about that. I was using the word canvas in a graphics sense. My canvas object is subclassed from JPanel. I'm using Swing for everything.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. In that case, it sounds like a concurrency issue. You could try wrapping the call to JOptionPane.showInputDialog in a SwingUtilities.invokeLater.
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic