• Post Reply Bookmark Topic Watch Topic
  • New Topic

No focus to Dialog box  RSS feed

 
Mohamed Manas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm developing a console application.
But for better interaction I am using Information Dialog box with the following code:


It works perfectly. But the problem is when the application is running when the Information Dialog Box appears for the first time it doesn't get the focus. I have to press ALT+TAB to access the information dialog box.
But from the second time onwards the information dialog box gets the focus automatically.
How can I prevent this problem?
Thanks in advance.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem arises out of parenting the dialog to a frame that has not been set visible. Try it with a null parent.
 
Mohamed Manas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, it doesn't seem to work.
No improvements yet.

Thanks for the help anyway.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mohamed Manas:
... it doesn't get the focus. I have to press ALT+TAB to access the information dialog box.
How can I prevent this problem?


You can subclass JOptionPane and override the showOptionDialog(). This method is the one in which the actual JDialog is created and displayed. Inside your overridden method you can call a toFront() after the dialog is shown. This should fix your problem.
 
Mohamed Manas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:


You can subclass JOptionPane and override the showOptionDialog(). This method is the one in which the actual JDialog is created and displayed. Inside your overridden method you can call a toFront() after the dialog is shown. This should fix your problem.


I tried to do as you have mentioned. But it didn't fix the problem. Because I couldn't find a toFront() method in the documentation for the JDialog. Please explain with a example.
Thanks.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mohamed Manas:

... Because I couldn't find a toFront() method in the documentation for the JDialog.


What to you mean you couldnt find the toFront() method?
You dont need to find it, but call it after dialog.setVisible(true).

JDialog inherits the toFront() from Window.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:

You dont need to find it, but call it after dialog.setVisible(true).

Well that could cause a problem. The JDialogs of JOptionPane are modal, and therefore the call to dialog.setVisible(true) will block the code until the dialog is closed. If you call dialog.toFront() after that the dialog will already be invisible, and there is nothing to bring to the front.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad. I should have thought of that.
In that case, I am wondering if dialog.setAlwaysOnTop(true) (called before the setVisible(true)) would be the proper thing to do.
[ July 23, 2008: Message edited by: Maneesh Godbole ]
 
Mohamed Manas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:
My bad. I should have thought of that.
In that case, I am wondering if dialog.setAlwaysOnTop(true) (called before the setVisible(true)) would be the proper thing to do.

[ July 23, 2008: Message edited by: Maneesh Godbole ]


First of all I didn't understand how to write the codes inside the overridden method (may be I am not matured enough in Java).
Can you give me the code for the overridden method.
Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!