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?
After you create another window, call toFront() on your JFrame that you want to be at the front. myFrame. setAlwaysOnTop(true);
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.
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.
JDialog(Dialog owner, String title, boolean modal) Creates a dialog box with the specified Dialog owner, title, and modality.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With