Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Focus on JPanel field inside a Confirm Dialog

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am using a showConfirmDialog



to get user input, user input fields are in a JPanel, i am passing that JPanel as "message" argument, (as can be seen from the code above, 2nd argument in showConfirmDialog method).

But when this dialog is opened, the focus by default is on "OK" button of the Confirmation Dialog.

Can someone please tell me, how to set focus on my JTextField, in JPanel inside Confirmation Dialog.

Regards,
Akhil
 
Author
Posts: 974
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Akhil Jain:
Can someone please tell me, how to set focus on my JTextField, in JPanel inside Confirmation Dialog.



The 'right' way is to essentially reimplement showConfirmDialog() so you can customize the JOptionPane it creates, but it may be simpler to use a kludge like this:



This used to work for me without the call to sleep(), but then something changed. As I said, it's a kludge.
 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi cole,

Though your hack worked just fine for me as well, except one problem, that the "OK" button is getitng focus, and the cursor comes inside the JTextField of a JPanel (type of having focus).

Is there any way to remove that focus from "OK" button completely?

AND

When you say re-implement the showConfirmDialog, what does it mean exactly. Do you mean to say that i should write a class which will extend JDialog.

can you give an example, where in, i can use the same thing, which i am using right now, but with custom implmentation of JDialog.

Note: the JPanel which i am passing as a message to the showConfirmDialog is also a seperate class which extends JPanel.

I am calling this showConfirmDialog method of JOptionPane in my main frame.
[ November 20, 2007: Message edited by: Akhil Jain ]
 
Brian Cole
Author
Posts: 974
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Akhil Jain:
When you say re-implement the showConfirmDialog, what does it mean exactly. Do you mean to say that i should write a class which will extend JDialog.



No, I mean that you should take a look at the JOptionPane source and do essentially what showConfirmDialog() does [actually, all the heavy lifting is in showOptionDialog()] yourself.

That way, for example, you can modify the JOptionPane after it is instantiated. If you call showConfirmDialog() there's no way to get your hands on it.
 
Brian Cole
Author
Posts: 974
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Akhil Jain:
[QB]Though your hack worked just fine for me as well, except one problem, that the "OK" button is getitng focus, and the cursor comes inside the JTextField of a JPanel (type of having focus).

Is there any way to remove that focus from "OK" button completely?



I don't think the OK button actually has focus, just that it has been set as the defaultButton of the JOptionPane's JRootPane. Is it just the appearance you are worried about, or is the behavior wrong too?
 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think, thats just the appearance...so i guess this is fine.

thanks for helping out in this.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!