Results 1 to 6 of 6
  1. #1
    dtmansy is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Question Any workarounds for JPasswordField in JDialog bug?

    My application has a JTextField and JPasswordField in a JDialog.
    When the dialog is displayed it is possible to enter text in the JTextField
    but not the JPasswordField. The JPasswordField gets the focus (cursor) but
    nothing happens when you type in the field. This is only happening on Linux
    (2.6.18-128.el5). It works fine on XP and Solaris 10. I am using
    java 1.5.0_11. I found a similar problem in the bugs.sun.com bug
    database (bug_id=6789984) . Sorry I can't post the link to it because
    the forum wont allow me to include a link because I'm a new member.

    I tried the test program in that bug report and it seems to exhibit the
    same behavior as my application. It works on XP and Solaris 10, but
    does not on Linux. Any ideas on how to work around this until there is a fix?
    I've tried manually setting the focus using requestFocusInWindow()
    but that does not seem to help. It appears the password field DOES have
    the focus, it is just not accepting input for some reason?

    I'm including the test program here for your convenience:

    ---------- BEGIN SOURCE ----------
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.*;

    public class JPasswordTest extends JDialog
    {
    JPasswordTest(String title)
    {
    super();
    setTitle(title);
    init();
    }

    private void init()
    {
    this.getContentPane().setLayout(new GridLayout(3,2));
    this.getContentPane().add(new JLabel("username:"));
    this.getContentPane().add(new JTextField(20));
    this.getContentPane().add(new JLabel("password:"));
    this.getContentPane().add(new JPasswordField(20));

    JButton exit=new JButton("exit");
    this.getContentPane().add(exit);
    exit.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    System.exit(0);
    }
    });

    this.pack();
    }

    /**
    * @param args
    */
    public static void main(String[] args)
    {
    SwingUtilities.invokeLater(new Runnable()
    {
    public void run()
    {
    JPasswordTest test = new JPasswordTest("test");
    test.setVisible(true);
    }
    });

    }
    }
    ---------- END SOURCE ----------

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    It is getting entered, but being hidden. See JPasswordField (Java Platform SE 6) -> setEchoChar(char)

    Then again, it may not be. I haven't seen the bug report, and don't have a linux on hand to test, so I can only suggest to try changing the echo Char.
    Last edited by masijade; 02-10-2009 at 08:02 PM.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Also, have tried simply continuing after having attempted to type something and have the program print out the result of getPassword ?

  4. #4
    dtmansy is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default

    No it is not hidden. Normally when you type in a JPasswordField, as you type each character the echoChar is echoed (by default '*') but with this bug
    nothing happens when you type. The cursor does not move. In my application
    (not in the test program posted on the bug website) if the focus moves away
    from this screen - for example if you hit the OK button and an error dialog is displayed saying the password field is required, and then you dismiss the error dialog, you are then able to enter text into the password field. Also, if you ALT-TAB and cycle through the windows on your desktop when you return to the java application you are able to enter text in the field. I notice with this test program that scenario does not work, so there must be something slightly different between my application and this one, but they still exhibit this same behavior of the JPasswordField being unusable initially. I think the bug may be some interaction of the focus manager and the native OS windowing and some confusion as to which window is active?

  5. #5
    msfs is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    I am seeing this exact same behavior with RHES 5.3 32-bit. Works fine on Windows.

    I have a simple login dialog (JDialog with a JTextField for the username, and a JPasswordField for the password). The JPasswordField gets the focus initially with the following code:

    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    passField.requestFocus();
    }
    });

    With the initial focus, you can type in the password field and see the echo chars. However, if you change the value in the username JTextField, and then come back to the JPasswordField (either with the mouse or with the Tab key), it does not accept any input - no echo chars or anything.

    Does anyone have a workaround? The problem still happens when I comment out all listeners and the initial request focus code above from the JPasswordField.

  6. #6
    msfs is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    If anyone runs into the same problem, this seems to be a Java bug that Sun has recently fixed on their end:

    Bug ID: 6801620 JPasswordField broken on JDK 6
    Bug ID: 6703772 Regression: JPasswordField doesn't always recognize AltGraph Keystrokes in Java SE 6
    Bug ID: 6680988 KeyEvent is still missing VK values for many keyboards

    Unfortunately, the fix won't be widely available until Java 7.

    As a workaround, you can call enableInputMethods(true) on your JPasswordField, and the problem should go away. However, this may open up a potential security risk, as noted in the JPasswordField API:

    NOTE: By default, JPasswordField disables input methods; otherwise, input characters could be visible while they were composed using input methods. If an application needs the input methods support, please use the inherited method, enableInputMethods(true).

Similar Threads

  1. setLocation on a JDialog is ignored
    By ScottVal in forum AWT / Swing
    Replies: 7
    Last Post: 01-13-2009, 07:35 AM
  2. Ask about JPasswordfield
    By yonghan in forum AWT / Swing
    Replies: 7
    Last Post: 09-14-2008, 11:54 AM
  3. help with jdialog
    By leonard in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2007, 05:37 AM
  4. Close a JDialog Programmatically
    By Marcus in forum Advanced Java
    Replies: 1
    Last Post: 07-06-2007, 04:06 PM
  5. problems with jDialog in a JFrame
    By bbq in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2007, 04:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •