Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on focus  RSS feed

 
Sharada Sreeram
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class extending JDialog - in this I take some input and also have a OK & a Cancel button. I want my OK button to be the default command button - basically, on enter from any field other than the text fields, I want my OK button code executed and also want this shown as the default button (basically with a heavier border).
How do I do this ? I tried the different JComponent methods like requestDefaultFocus etc. (been trying for quite a few hours now!)

TIA
Sharada
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
requestFocus() will make the button the default button.
To get OK to execute from a variety of actions you are going to need to set up listeners etc.
Perhaps if you post some code. . .
 
Sharada Sreeram
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found it - I had to use getRootPane.setDefaultButton (ok).
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!