JApplet focus for KeyListener

I have a JApplet that has a JFrame containing the UI. I want to capture the keyboard inputs via a KeyListener that I've written. My purpose is to capture the Page Up and Page Down keys to move forward through an array of images.
I've tried adding the Key Listener to the frame.getContentPane() and to the JFrame itself. Nothing happens. When I add the Key Listener to a specific control (like a JTextField), and mouse click to give focus, then press PageUp or PageDown, the listener does it's job and the images update correctly. That tells me the listener is correct. Now, I just have to "listen" on the correct object.
Any suggestions?

This was resolved by making the class (which extends JFrame) a KeyListener. Now, what I'm seeing is pageup/down works fine, until you click some "other" control (button, text field, etc...) at which point the KeyEvent isn't getting picked up. I'm not handling any key events anywhere else, and I can't force a "grabFocus()" on the JFrame as that method is not supported. I've also tried setting the JFrame as FocusTraversable(true) but that didn't affect anything.
Ideas?

Similar Messages

  • Problem with requesting focus for a list

    Hi there !
    What would be the right way to request focus for a list component ?
    I can use select() method to select some item from a list, but the list itself still hasn't got a focus until I click it.
    What I'd like to do is to be able to highlight some item from the list by using up and down arrow keys only, without clicking the list first =)

    The list is visible, but still this doesn't work.
    I think that the reason for this may be that I'm running this app on Nokia 9210 Communicator emulator. The emulator itself has had some not-so-minor problems...

  • App similar to stay focused for MacBook Air

    Is there an app similar to stay focused for MacBook Air?

    There is a way to see (in small window) short bits and parts of video movies, where they exist, in the iTunes application from the store page in there. My older Mac with earlier version of iTunes lets me browse Music, Movies, TV stores, from the sections on the iTunes application; years ago there was more direct content. They used to have a site page for some of those clips... I haven't looked lately.
    A screenshot of a video clip ^ from the iTunes Movie store, via iTunes in my Mac.
    If you browse the items for sale/rent, a few have a tiny triangle on them and this opens the little window where a preview runs. A few actual movies will have an option to see a preview or trailer-like video in a similar small window that opens up over the store screen.
    The older iTunes application in earlier Mac systems had various other features. In order to view movie trailer kinds of content streamed from the internet, you may have to look into a third party application or a web page.
    There may be a list of applications included with certain models of Mac portables
    and if you can find that name, that may be a talking point. The Store has lists of
    what software may be included in the most recent Macs in each products info.
    {There was no mention prior to your reply...
    that you did not want to make movies, btw.}
    Good luck & happy computing!
    edited.

  • Datagrid focus for cell

    Hi,
    how to set focus for perticuler cell or row in datagide
    using flex 3 .Flex 2 Beta 1:
    var __focusedCell:Object = new Object();
    __focusedCell.itemIndex = 1;
    __focusedCell.columnIndex = 2;
    dg.setFocusedCell(__focusedCell,true);
    Flex 2 Beta 2:
    var __focusedCell:Object = new Object();
    __focusedCell.rowIndex = 1;
    __focusedCell.columnIndex = 2;
    dg.setEditedItemPosition(__focusedCell);
    but this functions
    (dg.setFocusedCell,dg.setEditedItemPosition) are not working in
    flex 3.0. please let me know if any body known this one

    Perhaps you could try:
    myGrid.selectedItem = -1;

  • Request focus for message area

    Dear All,
    As my screen is long hence if an error comes we will require to scroll down so I have added a message area UI element and in do modify method of the view i have request focus to my message area but it is not working.  Below is the code which I have written:
    try{
              IWDMessageArea msgarea=(MessageArea)view.getElement("MessageArea");
            msgarea.requestFocus();
            catch(Exception e)
    Is there any other property or changes need to be made.
    Thankyou.
    Regards,
    Santosh

    Hi,
    In would say, create an input field at the top left corner of the screen. Set its width to zero and bind it to a context attribute say Va_ShowMesg of type string. Now insert a MessageArea UI element just below the inputfield to display all the erro message at the top left.
    Now if you request focus for the input field using the following code, the focus will automatically come to the Message Area as well.
    wdThis.wdGetAPI().requestFocus(wdContext.currentContextElement(),wdContext.getNodeInfo().getAttribute(
              wdContext.currentContextElement().VA__SHOW_MESG));
    You can call this code whenever you need to display message to user in the message area and shift focus of the screen to the message displayed.
    Regards,
    Tushar Sinha

  • Order of focus for swing components

    Hi All,
    I am in search of the way to definine the order of focus for swing components.
    I have a JPanel to which I can add multiple JButtons and JLabels. My problem is that when ever JButton comes, it should get the focus even though JLabel exists.
    If I drag the JButton on to JLabel then also it should be placed on top of the JLabel.
    Can any body help me to solve this problem.
    Thanks in advance,
    Regards,
    Roja.

    Hi,
    I am giving my sample code here.
              if (textButton != null) {
                   setUserTextPresentFlag(true);
                   textButton.setFocusPainted(false);
                   textButton.setContentAreaFilled(false);
                   textButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
                   textButton.setBounds(
                        editPosX,
                        editPosX,
                        textButton.getWidth(),
                        textButton.getHeight());
                        textButton.setRequestFocusEnabled(true);
    //                    textButton.grabFocus();
                        textButton.requestFocus();
    System.out.println("requestFocus isDisplayable::"+userTextImageButton.isDisplayable()+" isEnabled "+userTextImageButton.isEnabled()+" isFocusPainted "+userTextImageButton.isFocusPainted()+" isVisible "+userTextImageButton.isVisible()+" userTextImageButton.hasFocus() "+userTextImageButton.hasFocus());
    I am getting the following values for the system.out.println values.
    isDisplayable::false isEnabled true isFocusPainted false isVisible true userTextImageButton.hasFocus() false
    I didn't find a method to set displayable to true.
    could u find where the problem is?
    Thanks in advance,
    roja.

  • All focused for the movie The Amazing Spider-Man 2

    All focused for the movie The Amazing Spider-Man 2
    https://drive.google.com/forms/d/1yLXR8rBm1cHDSTRBL9EMbXGxMyjjYxfU804QLRPMIIw/viewform
    http://theamazingspiderman2now.wordpress.com/
    http://hdmedia.uservoice.com/knowledgebase/articles/352801-watch-the-amazing-spider-man-2-online-all-resource
    studios, at one point having James Cameron to direct, before being secured by Sony Pictures Entertainment. Sony hired comic

    Dolby Laboratories is potables the silver screen world with its new Dolby Atmos technology, the simply object-based cinema sound platform available in these times. Dolby Atmos unleashes the capability of sound in storytelling by outfitting sound experts
    the prominent exception to easily designation or feat medicine sounds anywhere in the movie theatre, not just where there happen to be speakers. The counting is what moviegoers venture avowed as the most engrossing and lifelike cinema sound experience ever.
    Introduced in April 2012, Dolby Atmos has been embraced by all the greatest Hollywood studios, six Doctrine Award® winning directors, and 12 Academy Award® winning sound mixers, among others. More than 450 Dolby Atmos screens have been installed or committed
    to in 40 countries with more than 150 exhibitors. More than 100 films from 10 selection countries—representing a adequate range of genres from order thrillers and spry fa to spirits and horror—have been or are scheduled to be released with Dolby Atmos sound
    since the first film debuted in June 2012.
    Dolby Atmos has customary detailed skill rewards from both the Hollywood Post Alliance and the Cinema Audio Federation. As the inventors of the only object-based audio scheme old in the cinema today, Dolby is efficacious in all respects with the Society of
    Manner Picture and Compel Engineers in driving adoption of standards for object-based audio.

  • Monitoring tool for performance focused for Ebusiness.

    Hi partners,
    We are going to evaluate some "monitoring" performance tools for an Ebusiness environment, so I would like to know if you can give any recommendations about any tool focused for Ebusiness environment.
    Any advice will be really appreciated.
    Thanks in advance.
    Francisco Mtz.

    二、     The following includes SGAgent for Oracle E-Business Suite Enterprise Edition monitor KPIs click here 。
    1.     SGAgent can monitor all KPIs those Oracle standard edition includes;
    2.     SGAgent can monitor more Oracle Instances 、more type database(Like DB2 MS SQL Server Sybase)、more Oracle E-Business Suite Instances at the same time and the same screen;
    3.     Oracle EBS Patch Monitor(KPI:Username、Patch Name、Patch type、language、Patch created date、last updated date);
    4.     Oracle EBS Profile Parameters monitor(KPI:Application username who updated the profile last、Last updated date、Application name、Profile Parameter name、Profile Parameter description、Language、Profile Value、Level ID、SQL Validation、Hierarchy type、Write allowed flag、Read allowed flag、last update by userid);
    5.     Oracle EBS Application users login monitor(KPI:Login ID、Oracle application login username、Login user description、Application users email address、Login start time、Login End time、login type、Operation system Session ID);Operation: Can kill user directly。
    6.     Oracle EBS Application users Activity(KPI:Program ID、Program type(Forms or Concurrent Programs)、Program name、Running Program Username、user description、Program start time、Program end time、cost time (Second)、Application User Email Address); Operation:Kill the running program(e.g. Forms ,Concurrent Programs, Concurrent Requests)。
    7.     Oracle EBS Discoverer Reports Top 10 running times per month(KPI:Instance name、month、Discoverer Report Name、Running times);
    8.     Oracle EBS Discoverer Reports Activity (KPI:SID,Serial#、Execute times、Oracle username、machine、os username、Program type、SQL、CPU Time 、PGA-ALLOCATED、PGA USED、PGA Freeable); Operation:kill the running Discoverer Reports directly。
    9.     Online realtime Suport:SGAgent user can press the button in the top menu,chat with TechWiz Engineers directly using text words。
    10.     Store and analyze Historical data
    11.     Remote monitor :SGAgent can send its output by FTP to a public IP. Then the clients can monitor his organization from the web with any device that support web browsing.
    Add my MSN;[email protected]

  • Since upgrading to Mavericks from time to time the focus for the cursor is misplaced when scrolling

    Since upgrading to Mavericks, from time to time the focus for scrolling is misplaced. If I click into the list of emails, the mail message in preview scrolls. If I click into the mailboxes column, the list of emails in my inbox scrolls. Have anyone else seen this issue?

    Since upgrading to Mavericks, from time to time the focus for scrolling is misplaced. If I click into the list of emails, the mail message in preview scrolls. If I click into the mailboxes column, the list of emails in my inbox scrolls. Have anyone else seen this issue?

  • Can you get focus for an invisible JFrame?

    I'm writing a program where I use a JFrame for user input, and, after receiving input, the JFrame goes invisible, leaving the desktop clear while the program continues processing in the background. I want the same JFrame to be called back with user keyboard input (e.g. F12), but I don't know how to get KeyListener to work because I cannot obtain focus on the invisible JFrame. Is this possible?
    If not, is there a similar way to work around the problem?
    Any help is appreciated, thanks!

    I don't think that you can have focus on an invisible frame (though I'm not sure) but a goos way around would be to show a small dialog that says "Currently working, press a key to go back to main screen" and add a key listener to this dialog instead of the invisible frame.
    But if you want to work in the background, maybe you'll have to run the dialog on a new thread for both to work at the same time.
    Hope it helps

  • Trouble with focus, swing & keyListener

    can anybody out there help me with this problem, I got stuck with:
    I create a JDialog in a JFrame & would like to add Keylistener to the JDialog as soon as it opens..........but the it doesn't seem to be working....

    Oops! As bbhangale pointed out, my previous post is incorrect. It should read as follows:
    dialog.getRootPane().getInputMap...
    dialog.getRootPane().getActionMap...Actually, I've created MyDialog, an abstract sub-class of JDialog. In it, I over-ride the createRootPane() method and delcare the abstract onDialogClose() method. Here's what that looks like:
    public abstract class MyDialog extends JDialog
       // Implement MyDialog wrappers for all the JDialog constructors
       public MyDialog()
          super();
        * Overriding this method to register an action so the 'Esc' key will dismiss
        * the dialog.
        * @return a <code>JRootPane</code> with the appropiate action registered
       protected JRootPane createRootPane()
          JRootPane rootPane = new JRootPane();
          rootPane.getInputMap( JComponent.WHEN_IN_FOCUSED_WINDOW ).
             put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "escPressed" );
          rootPane.getActionMap().
             put( "escPressed", new AbstractAction( "escPressed" )
             public void actionPerformed( ActionEvent actionEvent )
                onDialogClose();
          return rootPane;
        * This method gets called when the user attemps to close the JDialog via the
        * 'Esc' key.  It is up to the sub-class to implement this method and handle
        * the situation appropriately.
       protected abstract void onDialogClose();
    }Then, anytime I need a dialog, I sub-class MyDialog and implement onDialogClose() to do whatever I want it to do when the user presses 'Esc'.
    I swear I've been using it for quite some time now and it works beautifully!
    Jamie

  • Problem with gaining focus for JTextField in JTabPane

    I have 2 tabs. The first one has a "save to file" puush button, the seccond has two textfields. When I push the save button I get a warning that not all fields in the seccond tab are filled. If I choose the first button it shows me the seccond tab and searches for the first empty field. Then it should set the focus to that field but it doesn't. Here's the code:
    void goToEmptyField() {
            tabs.setSelectedIndex(1);
            JTextField field =  (nameField.getText().length() == 0) ? nameField : actionField;
            field.requestFocusInWindow();
        }The code for determining the first empty field works fine. I'm not sure if the seccond tab gets focus or just shows up. It doesn't have the light rectangle at the tab's description. Could anybody help me please?

    seems to work OK in this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      JTabbedPane tabs;
      JTextField nameField = new JTextField(20);
      JTextField actionField = new JTextField(20);
      public Testing()
        setLocation(400,300);
        setSize(300,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel jp1 = new JPanel();
        JButton saveBtn = new JButton("Save");
        saveBtn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            if(checkFields()) saveData();}});
        jp1.add(saveBtn);
        JPanel jp2 = new JPanel();
        jp2.add(new JLabel("Name: "));
        jp2.add(nameField);
        jp2.add(new JLabel("Action: "));
        jp2.add(actionField);
        tabs = new JTabbedPane();
        tabs.addTab("Tab 1",jp1);
        tabs.addTab("Tab 2",jp2);
        getContentPane().add(tabs);
      public boolean checkFields()
        if(nameField.getText().equals("") || actionField.getText().equals(""))
          JOptionPane.showMessageDialog(this,"field/s empty");
          goToEmptyField();
          return false;
        return true;
      public void goToEmptyField()
        tabs.setSelectedIndex(1);
        JTextField field =  (nameField.getText().length() == 0) ? nameField : actionField;
        field.requestFocusInWindow();
      public void saveData()
        JOptionPane.showMessageDialog(this,"Saving data...");
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Button focus for mnemonic control

    Does anybody know how to set the focus on a JButton, in order for the mnemonic key to work? I have a Frame with textarea and a button, and the button ("Close") is set with a mnemonic key (`C`). I just don't know how to set the focus on the button so that when I hit Alt + C, the window will be close. Here is my code sample:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BorderExample {
         private Frame f;
    private JButton close;
    private Panel p;
    private TextArea ta;
    public BorderExample() {
    f = new Frame("Border Layout");
    close = new JButton("Close");
    close.setMnemonic('C');
    close.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         System.exit(0);
    ta = new TextArea();
    ta.append("Hello World");
    ta.setEditable(false);
    public void launchFrame() {
    f.add(ta, BorderLayout.CENTER);
    p = new Panel();
    p.add(close);
    f.add(p, BorderLayout.SOUTH);
    f.pack();
    f.setSize(200, 200);
    f.setVisible(true);
    public static void main(String[] args) {
    BorderExample ex = new BorderExample();
    ex.launchFrame();
    Any suggestion is greatly appreciated.

    hi,
    this time i got ur exact problem. actually mnemonic control workes fine if all the components are in the same container. in ur example, they r in different panels. so, we need to make following changes :
    1) create a reusable action listener object, not the anonymous.
    2) call one method on the button panel : (methos in JComponent class, bur depricated since JDK1.3.)
    p.registerKeyboardAction(<action listener object>, <String action command>, KeyStroke.getKeyStroke(<key char value for mnemonic control>),JPanel.WHEN_IN_FOCUSED_WINDOW);
    this will fire the desirable event, even if u press alt-c while typing in text area.
    and regarding the grey color of text area, i am sorry about my previous reply. in disabled mode, background color doesn't change. just the text color changes and u can set that text color by calling this method of JTextComponent
    jtextcomp.setDisabledTextColor(Color c) ;
    hope this helps!!
    anshu

  • JApplet focus in JSP page

    I have an applet embeded in a JSP page. In this applet I have some text feilds for data entry. After the each data entry this field get validated . If the entered data is wrong then it popup a message using the JOptionPane.
    Now the problem. :- after message, I want to set back the focus to the respective fields. I had used setfocus(), grabfocus() etc..But nothing get worked.. Please advice ... tanx in advance...........
    Rgds
    Joe

    That's struts-specific. We're here in a JSP/JSTL forum.

  • Temporary focus for a popup?

    Hi, this is NOT URGENT, just a little brain teaser I have come upon myself.
    I have a calendar-like component that I want to display on a popup. The user may open it (with a button) and choose something with the mouse (which hides the popup and fires an event). No problem there.
    In the interest of not requiring mouse use (a big deal with me), I put in the handling value various keystrokes (<arrows/pageup/pagedn> move around; <enter> or <space> make selection; <escape> closes without selection, etc.). But I cannot figure out how to get the keystrokes delivered to my component because I can't seem to understand the temporary focus situation with popups.
    I have tried writing my own JPopupMenu and Popup implementations, tried to manually move focus around, tried tweaking around with the MenuSelectionManager to see if it is eating my keystrokes, but I can't get it to work, and I know that there must be something much simpler that I am not seeing.
    BTW, I am trying to not have to muck with the Input/Action Maps of the window (or of any ancestor component higher than the popup itself), though I have considered that I could change them when popup opens and restore them when popup closes. Like I said, there must be something much simpler, right?
    I wrote a small sample case, which I will include in case anyone cares to give this a look.
    SimplePanel just uses the arrow keys to change a Label among {N,E,S,W} values. It has a main that sticks it in a frame. The arrow key cause the label to change.
    SimplePopup provides a button that opens a JPopupMenu containing a SimplePanel. (To keep it super simple, I haven't even included a way to close the popup.) User can open the popup by hitting <space> on the focused button, but cannot manipulate the SimplePanel using the arrow keys.
    (I will post the code in separate messages)
    Thanks,
    /Mel

    I have a solution -- add a KeyEventPostProcessor that redispatches the KeyEvents to the component on the popup. For the example, I just implemented KeyEventPostProcessor in this class. Hurray for 1.4!!!
    My question from before still stands though: isn't there a simpler way to do this!??! Furthermore, why shouldn't this be the default behavior to begin with? (i.e. when a popup is opened on a window the popup becomes a temporarily focus root; when the popup is closed the (permanent) focus reverts to whoever had it before...)
    /Mel
    class SimplePopup extends JPopupMenu implements KeyEventPostProcessor
       SimplePanel content = null;
       SimplePopup(SimplePanel content)
          this.content = content;
          this.add(content);
       public boolean postProcessKeyEvent(KeyEvent e)
          if (this.isVisible())
             KeyboardFocusManager.getCurrentKeyboardFocusManager().redispatchEvent(this.content, e);
          return false;
       public void setVisible(boolean b)
          super.setVisible(b);
          if (b)
             KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(this);
          else
             KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventPostProcessor(this);
       public static void main(String[] args)
          JFrame frame = new JFrame();
          JPanel extraroom = new JPanel();
          extraroom.setBorder(new EmptyBorder(50,50,50,50));
          final JButton button = new JButton("show it");
          final SimplePanel spanel = new SimplePanel();
          final SimplePopup popupmenu = new SimplePopup(spanel);
          button.addActionListener(new ActionListener()
                                          public void actionPerformed(ActionEvent e)
                                             Point point = new Point(2, 2 + button.getBounds().height);
                                             Component window = SwingUtilities.getWindowAncestor(button);
                                             point = SwingUtilities.convertPoint(button,point,window);
                                             popupmenu.setLocation(point);
                                             popupmenu.setVisible(true);
          extraroom.add(button);
          frame.getContentPane().add(extraroom);
          frame.pack();
          frame.show();
    } // end class SimplePopup

Maybe you are looking for