File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

showInputDialog( ) focus

 
Rob Byrd
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • 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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic