addKeyListener in JInternalFrame?

Discussion in 'Java' started by Ron, Nov 22, 2005.

  1. Ron

    Ron Guest

    The following code does not seem to work:

    public class DocumentSetupDialog extends JInternalFrame {
    public DocumentSetupDialog {
    addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
    System.out.println("hello");
    }
    });
    }
    }

    Neither does getGlassPane().addKeyListener()

    How do I pick up key events in JInternalFrames?

    Thanks,
    Ron
     
    Ron, Nov 22, 2005
    #1
    1. Advertising

  2. Ron

    zero Guest

    "Ron" <> wrote in news:1132633221.618643.56110
    @g43g2000cwa.googlegroups.com:

    > The following code does not seem to work:
    >
    > public class DocumentSetupDialog extends JInternalFrame {
    > public DocumentSetupDialog {
    > addKeyListener(new KeyAdapter() {
    > public void keyPressed(KeyEvent e) {
    > System.out.println("hello");
    > }
    > });
    > }
    > }
    >
    > Neither does getGlassPane().addKeyListener()
    >
    > How do I pick up key events in JInternalFrames?
    >
    > Thanks,
    > Ron
    >
    >


    I haven't tried this, but I read somewhere that you should add the
    KeyListener to the DesktopPane, and in the keyPressed method use
    getSelectedFrame to see which JInternalFrame has the focus.
     
    zero, Nov 22, 2005
    #2
    1. Advertising

  3. Ron

    Ron Guest

    You know, this isn't working for a JDialog either.
     
    Ron, Nov 23, 2005
    #3
  4. Ron

    Michael Dunn Guest

    "Ron" <> wrote in message
    news:...
    > The following code does not seem to work:
    >
    > public class DocumentSetupDialog extends JInternalFrame {
    > public DocumentSetupDialog {
    > addKeyListener(new KeyAdapter() {
    > public void keyPressed(KeyEvent e) {
    > System.out.println("hello");
    > }
    > });
    > }
    > }
    >
    > Neither does getGlassPane().addKeyListener()
    >
    > How do I pick up key events in JInternalFrames?
    >
    > Thanks,
    > Ron
    >


    add this line

    public DocumentSetupDialog {
    setFocusable(true);//<----------------------------
    addKeyListener(new KeyAdapter() {
     
    Michael Dunn, Nov 23, 2005
    #4
  5. Ron

    Ron Guest

    Works. Thanks.

    Ron
     
    Ron, Nov 23, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eveline Franken
    Replies:
    1
    Views:
    686
    Maurizio
    Jul 25, 2003
  2. Cheng Thao
    Replies:
    0
    Views:
    390
    Cheng Thao
    Aug 6, 2003
  3. cccc
    Replies:
    0
    Views:
    1,852
  4. Barsum

    'JInternalFrame' in SWT

    Barsum, Jul 24, 2004, in forum: Java
    Replies:
    0
    Views:
    521
    Barsum
    Jul 24, 2004
  5. Lars Willich

    addKeyListener is NOT working

    Lars Willich, May 23, 2006, in forum: Java
    Replies:
    0
    Views:
    2,224
    Lars Willich
    May 23, 2006
Loading...

Share This Page