Getting which key is pressed without adding keylistener

I need to get which key is being currently pressed in valuechanged of treeselection event. i need to know which key is pressed before executing the code for treeselection event

1. In the future, note there is a Swing forum exactly for questions like this, questions about Swing:
http://forum.java.sun.com/forum.jspa?forumID=57
2. Can you explain your problem better?
Demo:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class KeyEventExample implements Runnable, KeyListener, TreeSelectionListener {
    @Override public void run() {
        JTree tree = new JTree();
        tree.addKeyListener(this);
        tree.addTreeSelectionListener(this);
        JFrame f = new JFrame("KeyEventExample");
        f.getContentPane().add(new JScrollPane(tree));
        f.pack();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    @Override public void keyPressed(KeyEvent evt) {
        System.out.println("keyPressed " + evt.getKeyCode());
    @Override public void keyReleased(KeyEvent evt) {
        System.out.println("keyReleased " + evt.getKeyCode());
    @Override public void keyTyped(KeyEvent evt) {
        System.out.println("keyTyped " + evt.getKeyChar());
    @Override public void valueChanged(TreeSelectionEvent evt) {
        System.out.println("valueChanged " + evt.getPath());
    public static void main(String[] args) {
        EventQueue.invokeLater(new KeyEventExample());
}

Similar Messages

  • Just bought an iMac put in password do not know which key to press to get started

    Just bought an iMac, it is setup asked to put in password which I have done now do not know which key to press to get started.

    Mac 101:  Get Started Using A Mac 

  • Which key is pressed

    what is the best way to khow which key off keyboard is presses?
    regards
    esmat.

    There is no native functionality in forms to do this - but if you are web deployed you can write a PJC to provide this information - see the KeyFilter sample available for Download from the Forms samples pages on OTN

  • How can i know which key i pressed?

    i defined F9,F10 as previous Item using Oracle Terminal.after the programme is executed,the user can use the function of Previous item,how can i know the key user pressed is F2 or F3?

    What's the big deal having more than one key to perform the same task? I don't believe I understood you properly....
    For instance, if you don't want end-users to press Ctrl+K to invoke LOV, one option is to "disable" this key combination using Oracle Terminal.
    Other option is the Keybidding API may help you. Look for it in Forms Builder Help. I don't think so, but maybe it could be usefull help...

  • How to find out which keys are pressed while a d&d drop occurs?

    Hi,
    while an item is dropped as part of a drag and drop operation, I would like to know if the user has pressed any keys.
    I use a TransferHandler for managing the d&d and this works fine with the system dependent modifier keys for move, copy and link. But as my application needs to perform special actions if, for example, 'p' is pressed while a drop occurs, I'm stuck:
    It looks like there is neither a way to poll for pressed keys [like Keyboard.isPressed('p')] nor are there any key events fired as long as the d&d operation is active.
    I've tried a adding a key listener, adding a key binding and using the KeyboadFocusManager but nothing seems to work.
    Any ideas?
    Thanks,
    Norb

    Hi,
    the question is where the focus would be - because as you know unless there is a record in InputMap and keys are usually only received by focused component anyway. I'd recommend hooking into Swing event queue, something like that:
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventQueue() {
        protected void dispatchEvent(AWTEvent event) {
            if (event instanceof KeyEvent && dragging) {
                // do something
    });

  • Keyboard only produces numbers and symbols regardless of which key is pressed.  Is there another option to deleting all and reloading Bootcamp?

    Repetitive pressing of one keyboard key produces different varied numbers and symbols.

    I actually ran into this same issue and created a standalone app that restores the Snow Leopard functionality. It seems to be a bug in the current implementation, hopefully Apple fix it soon.
    Check out my blog for the info and the download: http://nickbona.com/blog/2011/12/12/speak-selected-text-in-os-x-lion.html
    If you find it useful, feel free to share it with as many people as you'd like, just please post a link to that posting.
    Nick

  • My G4 powerbook starts up but with a black screen. The reset button does not work. Does anyone know the keys to press on restart please ?

    My G4 powerbook running OSX 10.3.9 starts up with  a black screen. The reset button is not working. Does anyone know which keys to press on restart please.?

    Try holding the shift key while booting to get Safe mode if possible.
    See links for more info.
    http://support.apple.com/kb/ht1564
    http://support.apple.com/kb/ht1455

  • IPhone letters don't pop up when keys are pressed

    You know how the letters pop up from under your finger when keys a pressed on the keyboard to let you know which key you press, well sometimes certain letters on my keyboard stop popping up. A restart fixes the key but a few minutes or hours (intermittent) later a different letter stops working. Anybody else have this problem?

    The problem seems to be related to the Auto-correct and Auto-capitalization feature. If I turn either one off (Settings->General->Keyboard), I don't have the problem but when both are on, it comes back. It also seems to affect the first character that I type in the input field.
    With both Auto features on, if I go to the login page of Twitter and type, say, a 'v' as the first character of the Username, a capital V is entered and the "V" pops up, but if I backspace, tap shift to go to lowercase and tap v again, the v does not pop up from the keyboard but it does show up in the username input field. I can reset things if I tap the Done button on the keyboard then tap in the username field to bring the keyboard back up. The problem is still there, but I can see it happen with a new letter if I want.
    Try it and post what you find. You don't have to have a Twitter account to see it happen and I'd be interested to know if it's consistent.

  • I keep losing the line at the top of the page which includes "file,edit veiw,bookmarks,history,help etc" I can get it back by pressing lt+F8 but it goes again when i press another key.how can I restore this permanently

    I have lsot the line in the toolbar spaces which include "file,edie,veiw,bookmarks,history,help"etc.Ican get it back by pressing Alt+F8 but it goes when I press any other key.How can I restore this permanently

    Thanks for the information, is this a windows 7 problem?

  • In chrome I'm getting green double underline hyperlinks to ads.  How can I get rid of this without adding more junk to the computer?

    I have both safari and chrome, because I'm used to chrome.  The only extension I have is Google docs.  I started getting green double underline hyperlinks to ads.  How can I get rid of this without adding more junk to the computer?  People suggest programs to do it, but how do I know they won't make it worse?
    Is someone from Apple here and can answer?
    Thanks!

    You may have installed the "VSearch" trojan. Remove it as follows.
    Malware is always changing to get around the defenses against it. These instructions are valid as of now, as far as I know. They won't necessarily be valid in the future. Anyone finding this comment a few days or more after it was posted should look for more recent discussions or start a new one.
    Back up all data before proceeding.
    Step 1
    From the Safari menu bar, select
              Safari ▹ Preferences... ▹ Extensions
    Uninstall any extensions you don't know you need, including any that have the word "Spigot," "Trovi," or "Conduit" in the description. If in doubt, uninstall all extensions. Do the equivalent for the Firefox and Chrome browsers, if you use either of those.
    Reset the home page and default search engine in all the browsers, if it was changed.
    Step 2
    Triple-click anywhere in the line below on this page to select it:
    /Library/LaunchAgents/com.vsearch.agent.plist
    Right-click or control-click the line and select
              Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "com.vsearch.agent.plist" selected. Drag the selected item to the Trash. You may be prompted for your administrator login password.
    Repeat with each of these lines:
    /Library/LaunchDaemons/com.vsearch.daemon.plist
    /Library/LaunchDaemons/com.vsearch.helper.plist
    Restart the computer and empty the Trash. Then delete the following items in the same way:
    /Library/Application Support/VSearch
    /System/Library/Frameworks/VSearch.framework
    ~/Library/Internet Plug-Ins/ConduitNPAPIPlugin.plugin
    Some of these items may be absent, in which case you'll get a message that the file can't be found. Skip that item and go on to the next one.
    The problem may have started when you downloaded and ran an application called "MPlayerX." That's the name of a legitimate free movie player, but the name is also used fraudulently to distribute VSearch. If there is an item with that name in the Applications folder, delete it, and if you wish, replace it with the genuine article from mplayerx.org.
    This trojan is often found on illegal websites that traffic in pirated content such as movies. If you, or anyone else who uses the computer, visit such sites and follow prompts to install software, you can expect more of the same, and worse, to follow.
    You may be wondering why you didn't get a warning from Gatekeeper about installing software from an unknown developer, as you should have. The reason is that the Internet criminal behind VSearch has a codesigning certificate issued by Apple, which causes Gatekeeper to give the installer a pass. Apple could revoke the certificate, but as of this writing has not done so, even though it's aware of the problem. This failure of oversight has compromised both Gatekeeper and the Developer ID program. You can't rely on Gatekeeper alone to protect you from harmful software.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • Configuring what element gets enter key press in JDialog?

    Hi all,
    In windows applications, some dialogs or windows, have a specific button that gets activated when enter is pressed. E.g. in a JDialog, the OK button would normally be activated when no button had focus. How do you set this to be? Is there some API call to do this? And is there some way to do the same with the escape key, so that cancel will always get triggered when its pressed?
    I just don't want to have to manually add a key listener to each component in the dialog that listens for the escape and enter buttons to be pressed.
    thanks,
    J

    As for the Esc key, there is nothing "out of the box" to do this. I created a JDialog sub-class to handle it, which I use in place of JDialog throughout my app. In the JDialog sub-class, over-ride the createRootPane() method as follows:
        * 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 pane = super.createRootPane();
          pane.getInputMap( JComponent.WHEN_IN_FOCUSED_WINDOW ).
             put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "escPressed" );
          pane.getActionMap().put( "escPressed",
             new AbstractAction( "escPressed" )
                public void actionPerformed( ActionEvent actionEvent )
                   onDialogClose();
          return pane;
       }then, create an abstract onDialogClose() method like the following:
        * 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();Alternatively, you could create a default implemenation of onDialogClose() instead of making it abstract; sub-classes could still over-ride it if they needed custom behavior.
    HTH,
    Jamie

  • I got a new lenovo desktop windows 8.1,installed itunes and synced my ihone 4 no problems. then i imported a cd of songs which showed up in recently added but not in main library ,therefore it did not sync to the iphone. how can i get new songs to ap

    i got a new lenovo desktop windows 8.1,installed itunes and synced my iphone 4 no problems. then i imported a cd of songs which showed up in recently added but not in main library ,therefore it did not sync to the iphone. how can i get new songs to appear in the main library and sync properly
    thanks
    john

    Check the songs are really not in the Music section of the library by clicking the magnifying glass in the search box and unticking Search Entire Library if it is ticked, then typing in the name of the album. If the tracks still don't show try closing iTunes and deleting a hidden file called sentinel from inside your iTunes folder. This should make iTunes run an integrity check on the database when you start it again. Make sure the tracks are checked before you try syncing again.
    tt2

  • How do I get a 23.98 sequence onto a dvd(29.97) without adding 3:2pulldown?

    Hello,
    I am having a hard time finding a process for burning 23.98 footage onto a DVD without having the method of 3:2 pulldown effecting the overall look. I have a sequence in Final Cut Pro that is 23.98. I’d like to burn it to a DVD but when the 3:2 pulldown is added the footage looks awful. I can’t conform the footage because audio will be out of sink and everything will be to fast. How can I take this .mov file and get it onto a DVD without visibly seeing the pull down. Does anyone have a suggestion? Please help or even start a conversation. I can’t do any work until I get this figured out.
    Thank’s
    Programs:
    Final Cut Pro
    Compressor
    Adobe Encore

    steveffg wrote:
    I don't believe it's adding pulldwn because each frame is smooth when you tab through each frame.
    You are right. I didn't see that you have this in a 24p sequence. You should be able to FILE>EXPORT>USING COMPRESSOR, select the preset that most closely matches the length of your movie, and encode. This should give you a progressive mpeg2 file that you can use.
    What is DVDSP ? I use envore but if that doesn't work than I assume DVDSP is a program.
    DVD Studio Pro, comes with Final Cut Suite. You may want to give it a try, maybe Encore is doing something strange with your file?
    K

  • Ever since I got the "new & improved" Firefox, I have had all kinds of problems the latest of which has left me without toolbars. How can I get back to the previous version?

    # Question
    Ever since I got the "new & improved" Firefox, I have had all kinds of problems the latest of which has left me without toolbars. How can I get back to the previous version? edit
    IS THIS A GAME?
    WHAT DETAILS DO YOU NEED?
    THE COMPUTER HAS WORKED FINE
    WITH THE OLD MOZILLA FIREFOX
    FOR YEARS.
    NO CHANGES HERE IN ANYTHING ELSE.

    Click the Firefox button, go to Add-ons, then Plugins and disable the following:<br><br>
    * Fun Web Products Plugin<br><br>
    * My Web Search<br><br>
    Both of these are adware/spyware and cause performance issues in Firefox.
    Next, click the Extensions menu link (above Plugins where you are) and remove the "Ask Toolbar".
    If the problem persists, please do the following:<br><br>
    #Click '''Help '''| '''Restart with Add-ons disabled'''.<br><br>
    #In the next menu which appears, checkmark: "'''Reset toolbars and Controls'''".<br><br>
    #Finally, click the button called "'''Make changes and restart'''".
    Just in case you weren't aware of it, you can right click the Back or Forward buttons to get a list of sites visited. If you'd like to see the return of the arrow on the Back button, install this add-on: https://addons.mozilla.org/en-US/firefox/addon/backforward-dropmarker/
    Last but not least, some of your plugins are seriously out of date which exposes your system to exploits. Please visit the [http://www.mozilla.com/en-US/plugincheck/ Plugins Check] page and update where necessary.
    See: http://www.adobe.com/support/security/bulletins/apsb11-08.html

  • Can I upgrade to Lion with an Intel iMac with 1 GB RAM. I am getting conflicting info (from Apple advisors) whether I need 2GB -which I can do by adding 1, or 3 -which apparently I can't do. Anybody successful in upgrading to Lion with 1 or 2 GB Ram?

    I am getting conflicting info (from Apple folks) whether I can upgrade to Lion with 1 GB Ram. Some are saying I need 2 (which I can do by adding memory) - or 3 (which I'm not sure I can do). Anyone running Lion with 1 GB? 2? I am at Leopard 10.5.8 to run some recording mixer which the company (Alesis) told me they weren't going to support drivers to Lion, but I guess they changed their minds. Am I clear on this? thanks.

    The hardware requirements for Lion are an intel Core 2 Duo processor and 2GB RAM.
    I wouldn't even both trying with 1GB, and even with 2GB Lion may struggle. If you intend to upgrade to Lion, can I suggest you max out your RAM. RAM is cheap at the moment.
    Which model mac mini do you have?

Maybe you are looking for

  • IWork not syncing with iCloud on iPad

    Okay, I am having the same problem a lot of people have been having. Namely, my iWork documents are not properly syncing with iCloud. They're stuck on either upload or download. Sometimes, I'll get a document to download, but it immediately begins to

  • Problem Highlighting Text in Acrobat 9 Std - Cursor-Highlight Mismatch

    I scan and often highlight the pdf documents I scan. I use Acrobat 9 Standard with Windows XP. Sometimes after I convert the page from an image to text so I can highlight text, the actual highlight does not cover the text I mark with my cursor. It so

  • IChat server will not start

    For reasons unknown, our server kernel panicked and had to be restarted. This machine is an OD replica. Since that time, we have not been able to restart iChat server. All other services appear to be working correctly. iChat was working without any p

  • Organising classical music

    I started to write this as a response to somebody else's query, but then I thought no, I'm asking for general guidance on the best way to organise classical music to be listened to on my Mac and on my iPod. I know that classical music lovers are a (t

  • Change Exchange Rate in VF02 T-code

    Dear Friends, I need to change the exchange  rate in transaction code VF02 before creating accounting entries, which field is presently grey field. Please provide the solution to change the exchange rate in VF02 transaction code. Thanks and Rgds, Hem