I am not able to login to my applet as the login dialog does not take the focu
In the login dialog of the applet it does allow the user to enter the password in to the field. Password field does not takes the focus. I tried with JTextfield and it is also having the same problem.
This happened
Every time Firefox opened
== When in installed 3.5.9 version. It is ok with 3.0 version
All Replies (3)
Can you use the Tab key?
I tried tab key and it is not working. It looks to me that any key on key board is not working. I can see the focus on "Ok" button but when i press "enter" key it does not work. I am able to use the mouse. I can click "ok" and "cancel" buttons of the dialog using the mouse click. If there is no password then i can login to the applet. After that it works normally and all the fields in the applet take focus. But if there is a password set, then i am not able to login as i cannot enter anything to the password field in the login dialog.
I also experienced the same bug.
This bug seems to manifest only on Mac OS X (tested on 10.5.2 and 10.6.2) and Firefox 3.6.x. It does not appear on other browsers for Mac OS X (Safari, Opera, Google Chrome). This bug does not appear for Firefox on other platforms (Windows or Linux).
Bug manifests if JDialog, containing JTextField is opened in JApplet.init() or JApplet.start() milestone methods.
JTextField is editable if dialog is opened for ex. from ActionListener.actionPerformed() method.
Here is sample code which illustrates this bug. The password input dialog is first shown during init() method and then it can be opened by pressing button "Open dialog". When dialog is opened in init() or start() method, JTextField does not receive focus. But when opened by pressing button, it is editable.
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class JPanelApplet extends JApplet { private static final int BTN_OK = 0; @Override public void start() { JButton button = new JButton("Open dialog"); final Frame frame = JOptionPane.getFrameForComponent(this); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { // From here JTextField will be editable char[] psw = showDialog(frame); System.err.println("You entered " + (psw == null ? "null" : String.copyValueOf(psw))); } }; button.addActionListener(listener); add(button); // when opened here, JTextField will not be editable showDialog(frame); } private char[] showDialog(Frame parent) { JPanel pane = new JPanel(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); final JPasswordField pswField = new JPasswordField(); pswField.setAlignmentX(Component.LEFT_ALIGNMENT); JLabel msgLabel = new JLabel(); msgLabel.setLabelFor(pswField); msgLabel.setText("Password:"); pane.add(msgLabel); pane.add(Box.createRigidArea(new Dimension(0,5))); pane.add(pswField); Object[] selections = new Object[]{"Ok", "Cancel"}; JOptionPane op = new JOptionPane(pane, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, selections, selections[BTN_OK]); JDialog dialog = op.createDialog(parent, "Enter password please"); dialog.setVisible(true); Object value = op.getValue(); dialog.dispose(); return ((value != null) && value.equals(selections[BTN_OK]))? pswField.getPassword(): null; } }
HTML code which opens applet:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Java Applet handling</title> </head> <body> <h1>Java Applet handling</h1> JPanel appplet: <applet code="JPanelApplet.class" width="150" height="20"></applet> </body> </html>
Tested with:
Mac OS X v10.6.2
Java JRE v1.6.0.20
Firefox v3.6.8
Java Embedding Plugin v0.9.7.3
Modified