Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to ensure that JDialog always stays on top

I have a JDialog that takes a name from the user. Behind the JDialog, is an applet. I dont want the user to access that applet until he has entered the name. I tried JDialog.setAlwaysOnTop(true), but the applet throws an AccessException error. So what I did was keep a while loop that will execute JDialog.setVisible(true) till the JtextField(input for user name) is empty (""). But for some reason this works really slow, meaning the JDialog loads, but it takes time to focus on the JTextField and even when the user types his name, it comes really slow... like one character in 2 seconds... Is there any other way for me to force the user to enter the name before accessing the applet?

like image 457
mithun1538 Avatar asked Apr 13 '10 18:04

mithun1538


People also ask

How do you make a JFrame always on top?

After you create another window, call toFront() on your JFrame that you want to be at the front. myFrame. setAlwaysOnTop(true);

How do I set JDialog to center?

If you really want to center a JDialog on screen, you can use code like this: // center a jdialog on screen JDialog d = new JDialog(); d. setSize(400, 300); d. setLocationRelativeTo(null); d.

What is the use of JDialog?

Class JDialog. The main class for creating a dialog window. You can use this class to create a custom dialog, or invoke the many class methods in JOptionPane to create a variety of standard dialogs. For information about creating dialogs, see The Java Tutorial section How to Make Dialogs.

What is Modal JDialog?

JDialog(Dialog owner, String title, boolean modal) Creates a dialog box with the specified Dialog owner, title, and modality.


1 Answers

Use a modal JDialog. For example the code in your init(...) method of JApplet might include:

JDialog dialog = new JDialog(SwingUtilities.windowForComponent(this));
dialog.setModal(true);
dialog.setSize(...);
dialog.setVisible( true );

Or you can just use a JOptionPane.showInputDialog(). Again you would just specify "this" as the parent component of the option pane.

like image 161
camickr Avatar answered Oct 21 '22 19:10

camickr