Results 1 to 6 of 6
  1. #1
    DigitalMan is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default JOptionPane, action listeners, and the Enter key.

    I have a bit of a problem I'd like to solve. I have a login dialog, in the form of a JOptionPane. Its contents are an Object array including a label, a JTextField, another label, and a JPasswordField. It then has custom-labeled OK and Cancel buttons.

    The idea is this. Dialog pops up, and if username-saving is OFF, the focus is in the user name field. If username-saving is ON, the user name is already in that field, so the focus should be on the password field. If the Enter key is pressed while in the username field, focus should move to the password field. If the Enter key is pressed while in the password field, it should hit the OK button.

    Now, on the main form, I would employ an ActionListener to do this (and already have where necessary). But the JOptionPane stops everything happening in the background, as far as I'm aware. Is there any way to accomplish this rather complicated setup, without having to make some whole new window?

    And also, how do I set default focus on one part of the Object array? If I try to single out the password field, it just goes back to the username field (but setting focus on a button works).

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Post the code.
    Ramya:cool:

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    For my money, if I wanted complete control over the dialog, then I'd just put everything in a JDialog and display it as a modal dialog.

  4. #4
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    If the Enter key is pressed while in the username field, focus should move to the password field.
    This is a great idea, but it is wrong. Sigh. Most look-and-feels follow the modes dictated by IBM-360 mainframe applications where the ENTER key caused an interaction with the mainframe. So to get from field to field one must use TAB instead of ENTER.

    You can probably make your design work, and it is a design I would prefer. However, it may not meet user expectations.

  5. #5
    DigitalMan is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    Hmm, alright then. JDialog is it; I suspect I'll need one of those for the preferences window anyways.

  6. #6
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    JDialog. Modal. Yuck. Sigh.

    I hate having to dismiss alert boxes by mouse-clicking them.

Similar Threads

  1. jTextField Listeners
    By user6123456 in forum AWT / Swing
    Replies: 6
    Last Post: 10-15-2009, 05:58 PM
  2. Help Updating Tree via Listeners
    By Seiki in forum SWT / JFace
    Replies: 1
    Last Post: 03-27-2009, 10:46 AM
  3. Seriously need help on my listeners!!
    By themburu in forum Java Applets
    Replies: 4
    Last Post: 05-26-2008, 10:41 AM
  4. Multiple listeners per event
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-03-2008, 10:06 AM
  5. Action Event and Listeners
    By lost1 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 04:26 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
  •