Key listeners without a component?

Hey guys,
So I have an application with several sliders, buttons, etc. and I would like to set shortcuts for certain parts of it. For example, when the user presses the "n" key, one of the sliders should increase in value. I have looked into this, and found that key listeners only work on a component that has the keyboard focus. Does this mean I should give my main JPanel the keyboard focus and make the shortcuts change the sliders in that listener? What happens if the focus changes from the main panel to one of the buttons and the key is then pressed, will it still call the key listener on the JPanel?
The best way would be if there was a listener that just listens to the keyboard and is called when a key is pressed, without any need for a specific component. Does anyone know of a way to do this? Thanks beforehand!
Cheers,
Lukas

Young_one wrote:
Well, the problem is I have 3 applets running on the same page, and so, they don't all have focus at the same time, but the key bindings need to work at any time, no matter which applet the user last clicked in. So I guess the question is if there is a way to create a listener that is not attached to a specific components focus. I would think that a listener that just listens to the keyboard doesn't have to specify a focus, but I guess it does? Thanks for all your help so far.Ah, I'm not an applet expert, but as far as I know, key binding and key listeners require that the app doing the listening have focus: with key listeners the component itself has to have focus, but with key binding, the component that is assigned the binding doesn't have to have focus, but at the very least the window that holds it does. I know of no way around this through standard Java.

Similar Messages

  • Getting key events without a jcomponent...

    Is it possible to get key events without adding a keylistener to a jpanel? I want a class of mine to manage input of it's own, but it has no reference to a jpanel. They don't necessarily have to be KeyEvents, but just some way to detect if a key has been pressed (like the arrow keys). How can I do this? Thanks.

    Lots of components can listen for key events.
    What does your class subclass?It doesn't subclass anything. I am creating a custom menu system for my game using images I have made for the tileset. I would like it to handle some keyboard events of its own. (Like if the down arrow is pressed, it will move the focus down to the next component on its own). Right now I am currently passing the key events from my fullscreen jpanel to the menu class and it is handling them that way. Thanks.

  • How to listen for inputs without a component? For creating bots

    I mean, for example, I want to write a a program that listens for keys f12 to (for example) skip the track in a media player and f11 to skip back. Thinks like the like :P. But I want to do this without any component, becasue the program won't have the focus at all.
    If it is needed to create a dll just tell as much as you pacience affords.

    I mean, for example, I want to write a a program that
    listens for keys f12 to (for example) skip the track
    in a media player and f11 to skip back. Thinks like
    the like :P. But I want to do this without any
    component, becasue the program won't have the focus
    at all. >Translation : I need a system keylogger.
    You can't do this in Java. And it will be OS specific.

  • "c" key types without being hit

    I have a MacBook Pro 17" late 2011 - the "c" key types without being hit. Any idea what could be causing this?

    Probably a stuck key or some other hardware issue with your keyboard.

  • Subject: Displaying key figures without currency unit in BEX reports

    Hello,
    Is it possible to display key figures without currency unit in BEx reports? For example; Material Costs 1000 EUR
    should be shown as 1000. Currency unit EUR and also scaling factor (*1000 EUR) does not interest us.
    When we use display options in query properties, we just see an option of displaying key figures with/without scaling factors, which does not solve our problem.
    Thanks for your reply.
    Regards,
    Nuran Adal

    Hi Eugene,
    thank you very much for your quick reply. We have very detailed reports with min. 10 columns, I should have defined 10 more formula columns to realize this (NODIM), but anyway there is no other way to do this, am I right?
    Best Regards,
    Nuran

  • Is it possible to create a component without a component controller?

    Hi every one,
    Is it possible to create a component without a component controller?If yes , how and what is the purpose of this?
    Thanks in advance. Points will be rewarded.

    Hi Prosun Bondopadhyay  ,
                   Component controller is the base of a wda component. its can be considered as the base class. all the other views can be considered as the sub classes of component  controller. so without the base class there is no existence for sub class rt?
    like we can use all the methods and attributes of a component controller(main class) across all the view(sub class) and the viceversa is not possible.
    hence we cannot create a wda without component controller.
    Regards
    Sarath

  • UIBB key is not valid (Component FPM_LIST_UIBB, Config ID HRESS_CC_W4_US, Instance ID )

    Hello All,
    I want to add a column in overview screen for W4 tax service for USA. I have created a new custom component configuration by copyning HRESS_CC_W4_US.
    And trying to assign this config in Z_HRESS_CC_W4_OVP_US. While doing so I get an error -
    UIBB key is not valid (Component FPM_LIST_UIBB, Config ID HRESS_CC_W4_US, Instance ID )  
    Any thoughts?
    Thanks,
    Bhushan

    Hi Bhushan,
    Goto SE80 and select Webdynpro Component/Interface
    and give FPM_LIST_UIBB, Press Enter.
    Then Goto Webdynpro Configurations and Select HRESS_CC_W4_US -> Select 'Start Configurator'
    It will open Browser where you can see the Other Functions button there select 'Create Enhancement'
    and name it as Z_HRESS_CC_W4_US or what ever name you want starting with 'Z_'.
    you need to save this in to your own Package name.
    Then click on Change button and goto 'Configure Columns' and add your required Column and save it.
    Regards,
    Mohsin.

  • Generate Key Events without pressing key???

    Hi,
    Is it possible to generate key events without pressing a key in swing???
    i dont know if the question is logical or not, but just i want to generate some display as if the key is pressed by the user
    Ashish

    assuming c represents a text field.
    This will type the character 'a' in the text field:
    c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_TYPED, 0, 0, KeyEvent.VK_UNDEFINED, 'a') );
    This will invoke Ctrl+F1, which will show the tool tip for the text field:
    c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_PRESSED, 0, KeyEvent.CTRL_MASK, KeyEvent.VK_F1) );

  • Kinect without vision component.

    I could learn from some web site,it is requirement both Labview and vision component to get and use output from Kinect with Labview.
    Is is possible to use output from Kinect without vision component?Because I don't have licence of this component and I need to get and use only depth info from kinect to subject.
    It means I don't need any RGB image and depth image etc....
    Please advise if I can connect and use Kinect without vision component.
    Thanks for all

    My own mistake. Trigger in database that truncated my date-field. Stupid me!

  • Messages show without message component

    Hello,
    in netweaver 2004s, sp09, we use in webdynpro for abap
    "messages show without message component"
    but in netweaver 2004s, sp12 we don´t find the option.
    Is this option depricated?
    Best regards
    Oliver Prodinger

    Hi Oliver,
    we made this change together with changes in the message area in SP11. These changes were done due to usability and UI Design specifications. Futhermore there are missing features implemented.
    For details have a look at:
    http://help.sap.com/saphelp_nwmobile71/helpdata/en/d8/2a934259a5cb6ae10000000a155106/frameset.htm
    Regards,
    Rainer

  • How to listen a key event without having any window component

    Hi all,
    I would like to know how can I listen key events from an application that doesn't use windows
    Thanks

    yoiu can make a Thread run inside your application. This will listen for inputs in the command line. For examplethis is part of a chat server (on the console) with let the server manager to enter messages or commands.
    The message or command entered on the console by the user is catched and processed as a String. The string is passed to the processConsole() method, you must define yourself.
    Th Thread is never stopped, so the user may enter any message at any time
    The core of you application should also be a Thread for better performance, but maybe it will also work without. Jst try and provide needed importstatements.
    Runnable runInput = new Runnable() {
            public void run() {
              while(true) {
                try {
                  byte buffer[] = new byte[255];
                  System.out.print(prompt);
                  System.in.read(buffer);//, 0, 255);
                  String inputString = new String(buffer, "Default");
                  processConsole(inputString);
                catch(NullPointerException npe) {
                  System.out.println("Syntax error");
                catch(Exception e) {e.printStackTrace(); }
          Thread inputThread = new Thread(runInput);
          inputThread.start();

  • Key Listening without a textfield or similar

    Ok, I want to let the program call a method when a key is pressed, but so for I have only been able to do this when i added a KeyListener to an object like a textfield.
    You can imagine this is a little bit annoying. I want something that listens to my Keys without some field. A panel was quite hard to implement and then I read something about ProcessKeyEvent and if you want this to work you have to do SOMETHING with enableEvent(), but I have no idea what. Can anybody tell me plz or give me another solution to this problem.

    I think JComponents can listen for KeyEvents (as a previous post explains, there should at least be some component available to listen for the events)
    The code below works for my JTree based component.
    tree.addKeyListener( new HierarchyTreeKeyListener(this) );Where the listener class looks like...
         class HierarchyTreeKeyListener extends KeyAdapter{
              HierarchyTree tree;
              public HierarchyTreeKeyListener(CTree treeIn){
                   tree = treeIn;
              public void keyTyped(KeyEvent kt){
                   //get a handle on the selected node. This will be the root for the search
                   DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
                   //System.out.println("selected node: "+selectedNode);
                   char key = Character.toLowerCase(kt.getKeyChar());
                   boolean found = false;
                        DefaultMutableTreeNode queryNode = (DefaultMutableTreeNode)tree.charSearch(key, selectedNode);
                        if( queryNode != null ){
                             expandPath( queryNode );
              }//end of method
         }//end of class HierarchyTreeKeyListener

  • Af:inputListOfValues sets value of first item in result set when using enter key or tab and component set to autosubmit=true

    I'm using JDev 11.1.1.6 and when I type a value into an af:inputListOfValues component and hit either the enter key or the tab key it will replace the value I entered with the first item in the LOV result set. If enter a value and just click out of the af:inputListOfValues component it works correctly. If I use the popup and search for a value it works correctly as well. I have a programmatic view object which contains a single transient attribute (this is the view object which is used to create the list of value component from) and then I have another entity based view object which defines one of its attributes as a list of value attribute. I tried using an entity based view object to create the LOV from and everything works as expected so I'm not sure if this is a bug when using programmatic view objects or if I need more code in the VOImpl. Also, it seems that after the first time of the value being replaced by the first value in the result set that it will work correctly as well. Below are some of the important code snippets.
    Also, it looks like it only doesn't work if the text entered in the af:inputListOfValues component would only have a single match returned in the result set. For instance given the result set in the code: Brad, Adam, Aaron, Fred, Charles, Charlie, Jimmy
    If we enter Cha, the component works as expected
    If we enter A, the component works as expected
    If we enter Jimmy, the component does not work as expected and returns the first value of the result set ie. Brad
    If we enter Fred, the component does not work as expected and returns the first value of the result set ie. Brad
    I also verified that I get the same behavior in JDev 11.1.1.7
    UsersVOImpl (Programmatic View Object with 1 transient attribute)
    import java.sql.ResultSet;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import oracle.adf.share.logging.ADFLogger;
    import oracle.jbo.JboException;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    // ---    File generated by Oracle ADF Business Components Design Time.
    // ---    Wed Sep 18 15:59:44 CDT 2013
    // ---    Custom code may be added to this class.
    // ---    Warning: Do not modify method signatures of generated methods.
    public class UsersVOImpl extends ViewObjectImpl {
        private static ADFLogger LOGGER = ADFLogger.createADFLogger(UsersVOImpl.class);
        private long hitCount = 0;
         * This is the default constructor (do not remove).
        public UsersVOImpl () {
         * executeQueryForCollection - overridden for custom java data source support.
        protected void executeQueryForCollection (Object qc, Object[] params, int noUserParams) {
             List<String> usersList = new ArrayList<String>();
             usersList.add("Brad");
             usersList.add("Adam");
             usersList.add("Aaron");
             usersList.add("Fred");
             usersList.add("Charles");
             usersList.add("Charlie");
             usersList.add("Jimmy");
             Iterator usersIterator = usersList.iterator();
             setUserDataForCollection(qc, usersIterator);
             hitCount = usersList.size();
             super.executeQueryForCollection(qc, params, noUserParams);
        } // end executeQueryForCollection
         * hasNextForCollection - overridden for custom java data source support.
        protected boolean hasNextForCollection (Object qc) {
             Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
             if (usersListIterator.hasNext()) {
                 return true;
             } else {
                 setFetchCompleteForCollection(qc, true);
                 return false;
             } // end if
        } // end hasNextForCollection
         * createRowFromResultSet - overridden for custom java data source support.
        protected ViewRowImpl createRowFromResultSet (Object qc, ResultSet resultSet) {
             Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
             String user = (String)usersListIterator.next();
             ViewRowImpl viewRowImpl = createNewRowForCollection(qc);
             try {
                 populateAttributeForRow(viewRowImpl, 0, user.toString());
             } catch (Exception e) {
                 LOGGER.severe("Error Initializing Data", e);
                 throw new JboException(e);
             } // end try/catch
             return viewRowImpl;
        } // end createRowFromResultSet
         * getQueryHitCount - overridden for custom java data source support.
        public long getQueryHitCount (ViewRowSetImpl viewRowSet) {
             return hitCount;
        } // end getQueryHitCount
        @Override
        protected void create () {
             getViewDef().setQuery(null);
             getViewDef().setSelectClause(null);
             setQuery(null);
        } // end create
        @Override
        protected void releaseUserDataForCollection (Object qc, Object rs) {
             Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
             usersListIterator = null;
             super.releaseUserDataForCollection(qc, rs);
        } // end releaseUserDataForCollection
    } // end class
    <af:inputListOfValues id="userName" popupTitle="Search and Select: #{bindings.UserName.hints.label}" value="#{bindings.UserName.inputValue}"
                                                  label="#{bindings.UserName.hints.label}" model="#{bindings.UserName.listOfValuesModel}" required="#{bindings.UserName.hints.mandatory}"
                                                  columns="#{bindings.UserName.hints.displayWidth}" shortDesc="#{bindings.UserName.hints.tooltip}" autoSubmit="true"
                                                  searchDesc="#{bindings.UserName.hints.tooltip}"                                          
                                                  simple="true">
                              <f:validator binding="#{bindings.UserName.validator}"/>                      
    </af:inputListOfValues>

    I have found a solution to this issue. It seems that when using a programmatic view object which has a transient attribute as its primary key you need to override more methods in the ViewObjectImpl so that it knows how to locate the row related to the primary key when the view object records aren't in the cache. This is why it would work correctly sometimes but not all the time. Below are the additional methods you need to override. The logic you use in retrieveByKey would be on a view object by view object basis and would be different if you had a primary key which consisted of more than one attribute.
    @Override
    protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i) {
        return retrieveByKey(viewRowSetImpl, null, key, i, false);
    @Override
    protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, String string, Key key, int i, boolean b) {
        RowSetIterator usersRowSetIterator = this.createRowSet(null);
        Row[] userRows = usersRowSetIterator.getFilteredRows("UserId", key.getAttribute(this.getAttributeIndexOf("UserId")));
        usersRowSetIterator.closeRowSetIterator();
        return userRows;
    @Override
    protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i, boolean b) {
        return retrieveByKey(viewRowSetImpl, null, key, i, b);

  • Moving the Focus with the TAB key in a JTextArea Component

    Dear Friends,
    I have exhausted all options of moving focus from JTextArea to next component. I have also tried all suggestions available in this forum. But i'm not able to solve my problem. Can any one help me.
    Thanx in advance.

    I had the same problem before. Here is what i did.
    JTextArea txtArea = new JTextArea(2,15);
    Set forwardTraversalKeys = new HashSet();     
    forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));          
    txtArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,forwardTraversalKeys);          
    Set backwardTraversalKeys = new HashSet();          
    backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));          
    txtArea.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardTraversalKeys);
    JScrollPane scrollPane = new JScrollPane(
         txtArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // the scrollbar of the JScrollPane is focusable that's why it requires
    // another TAB key to transfer the focus.
    scrollPane.getVerticalScrollBar().setFocusable(false);

  • Production Orders without material - component reservations in APO

    Hi All,
    We are using transaction CO07 to create a production order without material. We have four materials in the BOM for this production order. One is an input product and three are output products. My intention is to have the components on this BOM show up in APO as reservations or something else that will be considered in our planning.
    At this point I am not able to see anything in APO system (e.g order reservations) like I would with a regular production order with material. Does anyone have any experience with this functionality or know if it is supported by SAP?
    Thank you,
    Paul

    Hi Paul,
    It is an interesting case, a don't know if you have solved it. Anyway, here is my suggestion -
    1) If you want to see a reservation in APO for a component, you need to make sure that the header product exists in APO as well, and the production order for this header has also been CIFed over to APO. This is the first check.
    2) If the first check is OK, then you should check that all the 3 header products exist in APO (In your case, you have 3 three header products). And then, the production order appears for all the 3 products in product view.
    With the above checks, I am certain, you should see the reservation for the component, else it is an ieal OSS candidate.
    Thanks,
    Prashant Ghule

Maybe you are looking for

  • Post 10.4.11 problems w/attachments & .mac account

    Two problems which have come up since updating to 10.4.11. Whether it's an OS issue or not I don't know. 1) When I attach a QT movie to an email, instead of the player showing up in the message body at its normal size it views as this tiny little thi

  • Mass maintenance prob (urgent)

    Dear Friends, Through Existing LSMW, I am able to create the CH ID & CENVAT Field. When i need to overwrite the same, the message given by system is SV 009 "an entry already exist with this messege". Pls. Suggest the solution. This is requred for Mas

  • Background mrp in mdbt

    i want to run mrp in background for my new plant. i created variant for that plant and sched weekly and also i defined parallel processing in MRP. but mrp happened without selection of material??? there is no error msg in list of scheduled request...

  • HP Pavilion g6-2380sa

    Hi, I have purchased HP Pavilion g6-2380sa a week ago. It says on Hp website Discrete Dedicated Graphics card Option. How could i upgrade the graphis card and will it void my warranty? 

  • IMac Serial Number

    Hi. Since having the MLB changed on my iMac due to USB failure, I have no serial number. I am not prepared to lug the machine back to the Genius bar, does anyone know how I can reinstate the serial number please? Since the MLB change, I cannot log in