How to block JTree key event listeners

I have a JToolbar I am managing keyboards events for (e.g. PageUp, PageDown, right, left, up, down). I also have a JTree in another panel. I have to use 'Alt + PageUp' instead of PageUp because, if I use 'PageUp' (without also using the Alt key), and, the JTree gets the focus, then the JTree will respond to 'PageUp' instead of my JToolbar.
I have my key actions in a 'getKeystrokeActions()' method which I pass the JToolbar into so I tried passing the JTree to the same method. This doesn't quite do what I want as both components now respond to a 'PageUp' key event.
There must be some way to tell the JTree not to handle key events but I can't seem to find it. Any help much appreciated.

Remove the key listeners?
JTree tree = new JTree();
for(KeyListener listener : tree.getKeyListeners()) {
    tree.removeKeyListener(listener);
}Another option would be to just do
tree.setFocasable(false);

Similar Messages

  • How to block execution of event listeners

    Hi all,
    JDev version : 11.1.1.6
    My requirement is that I want to block all event listeners like ActionListeners, SelectionListeners, DisclosureListeners, RowDisclosure listeners when the screen is opened in readonly mode.
    I could block ActionListeners by disabling command links and command buttons etc.
    But there's no way to block SelectionListeners, DisclosureListeners, RowDisclosure listeners.
    So Is there any common code which can block all listeners?
    Or is there any EventController or something like that which will allow me to control event execution?

    I would have if it was just one screen.
    There are hundreds of screens.
    Anyways, can't I use any javascript to do this? There are some interfaces like EventListeners , classes like EventConsumer etc. Do none of them provide feature to block event listeners?

  • 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();

  • How to create native key events

    Hello
    can someone tell me please if (and if yes, how) it is possible to create native, therefore by the underlying recognized key events? My Java-App needs to send several key inputs which are also required to be noticed by Windows...
    Thanks
    Matthias

    see java.awt.Robot

  • How I get a key event ???

    I have a AWT application. I need to request a AWTEvent from keyborad. How I request a F12 key ??? Thanks for any help...

    You can add a KeyListener object to any class that inherits from Component (which pretty much means any AWT object). So, just create a new KeyListener Object, and add it to your main application panel (assuming this is something you want to catch on your whole app). Inside your KeyListener, override the keyPressed method, which takes as an argument a KeyEvent object. Inside the keyPressed function, you can see if the F12 key was pressed by doing the following :
    public void keyPressed(KeyEvent theEvent)
    if(theEvent.getKeyCode() == KeyEvent.VK_F12)
    //your code here
    This should work. Any other questions (like how to use other keys), consult the API for java.awt.event.
    Ed

  • Hlep in deleting Componantes using Key event listeners.

    Hi All,
    I am tring to write a GUI program. I am dragging componets from the left side of the panel to the right side of the panel. Everything works well as of now. But i am tring to delete the componets which i placed on the right side of the paenl using key stroke events. Can anyone tell how this can be done. I have like labels and textfield componeets.
    Please help
    Smitha

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    public class KeyDeletion extends JPanel {
        JComponent selectedComponent;
        public KeyDeletion(JFrame f) {
            setLayout(null);
            Dimension d = new Dimension(65,25);
            for(int j = 0; j < 4; j++) {
                JLabel label = new JLabel("label " + (j+1),
                                           JLabel.CENTER);
                label.setBorder(BorderFactory.createEtchedBorder());
                int x = 20 + j*(d.width + 25);
                int y = 20 + j*(d.height + 75);
                label.setBounds(x, y, d.width, d.height);
                add(label);
            addMouseListener(ma);
            registerKey(f);
        /** Press the "x" key to delete selected label. */
        private void registerKey(JFrame f) {
            JRootPane jrp = f.getRootPane();
            int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
            jrp.getInputMap(c).put(KeyStroke.getKeyStroke("X"), "DELETE");
            jrp.getActionMap().put("DELETE", deleteAction);
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            KeyDeletion panel = new KeyDeletion(f);
            f.add(panel);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        private MouseAdapter ma = new MouseAdapter() {
            Border etched = BorderFactory.createEtchedBorder();
            Border select = BorderFactory.createLineBorder(Color.red);
            JComponent lastSelection;
            public void mousePressed(MouseEvent e) {
                Point p = e.getPoint();
                Component[] c = getComponents();
                boolean haveSelection = false;
                for(int j = 0; j < c.length; j++) {
                    Rectangle r = c[j].getBounds();
                    if(r.contains(p)) {
                        setSelection(c[j]);
                        haveSelection = true;
                        break;
                if(!haveSelection && selectedComponent != null) {
                    setSelection(null);
            private void setSelection(Component c) {
                selectedComponent = (JComponent)c;
                if(c != null)
                    selectedComponent.setBorder(select);
                if(lastSelection != null)
                    lastSelection.setBorder(etched);
                lastSelection = selectedComponent;
        private Action deleteAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                if(selectedComponent != null) {
                    remove(selectedComponent);
                    selectedComponent = null;
                    repaint();
    }

  • How to block the workflow event

    hi all,
    we use the custom BAPI to trigger the workflow.
    in the custom BAPI we used <b>assigned</b> event from the <b>BOR object IFARCH21- it's related to SAP archive link .</b>. the custom BAPI is conatins the API's of  create a shipment,and shipment cost based on this opearations billing wii be done.....now the user will get the <b>error message</b> in SAP workplace from this BAPI.
    now i want to block the billing creation.
    please give a suggestion on this...
    regards
    Sukumar<b></b>

    Hi,
    Can you clarify a bit further????
    I think you have used SAP_WAPI_CREATE_EVENT in your BAPI to create the event "assigned". This event gets triggered whenever a shipment is created and the workflow send out a message to the inbox. Now you want to deactivate this message that is being sent. i.e in other words you want to disonnect the workflow itself from being triggered.
    If i am right in understanding your requirement then you will have to deactivate the linkage to the workflow that sends out the mail in the transaction SWETYPV. Or you will have to comment out the code written for SAP_WAPI_CREATE_EVENT.
    Thanks,
    Prasath N

  • IE7: How to block F1 key to show windows help in java applet?

    Question
    My applet use F1 shotcut key in each popup dialog(JDialog) to show application
    help, IE6 works correct, but IE7 shows windows help also besides
    applicaiton help.
    By the way, when applet got the focus, the windows help do not popped up
    when press F1 key. Who can help me?
    The owner of the JDialog is sun.plugin.viewer.frame.IExplorerEmbeddedFrame
    which is get by the following code:
    Frame jFrame = null;
    Container f = getParent();
    while ((f != null) && (!(f instanceof Frame)))
    f = f.getParent();
    if (f == null)
    jFrame = new Frame();
    else
    jFrame = (Frame)f;
    } //else

    In my testing, I found out that this works in IE7:
    <body onhelp="return false;">
    But if you call a function that returns false, then it doesn't work, i.e., the following doesn't work:
    function donothing() {
    return false;
    <body onhelp="donothing();">
    In the applet codes, this seems to be a problem only when the dialog owner is IExplorerEmbeddedFrame. When I set the owner to null, then pressing F1 no longer pops up IE help window.
    Edited by: bkyd on May 8, 2008 2:06 PM

  • How to handle key events in iphone

    I want to be able to detect physical keyboard (e.g. bluetooth) events in an iOS app.
    In Mac, there is a class NSEvent which handles both keyboard and mouse events, and in ios (iphone/ipad) the counterpart of NSEvent is UIEvent which handles only touch events. I know ios API does not provide this functionality, but how can i handle key events in iphone???

    in my application header part of the page is common of all page. header.jsff contains comandmenuItem named "proceduralhelp". if I click proceduralhelp a pop up opens .
    in my login page when first time I open popup and press escape popup is not closing.
    rest of the cases after login escpe will cose the popup.
    only on the loginpage that to for the first time it is not closing when pressing up on escape key. (then we click on close button. and once again open the popup in loginpage now if we press escape it works).
    Thanks,
    Raghavendra.

  • Tricky Block Key Events in JTable

    Iam using a JTable . I donot want to use CustomTableModel to block the key events but I want to consume the keyevents as and when the user types in . In other words block the user from editing the cell but I donot want to make the cell un-editable . THis is a bit tricky I hope I have a solution for this

    Not sure exactly what you want but maybe this will give you some ideas:
    table = new JTable(model)
         protected void processKeyEvent(KeyEvent e)
              int column = table.getSelectedColumn();
              int row = table.getSelectedRow();
              if( row == ?? && column == ?? )
                   e.consume();
               else
                   super.processKeyEvent(e);
    };

  • How to generate key events to a componet without keyboard

    I want to generate a key event, a Keylistener is already there, (in fact, java3D's KeyNavigatorBehavior). I want to use other input methods instead of key pressings, so how I generate the key event manually
    thx,

    Look at java.awt.Robot. It has a keyPress() method to simulate key presses.

  • How to catch key events

    Hello!
    I have a component which extends JPanel. Now I dynamically add a JTextField as a child to this component. The problem is: when the textfield has focus, how can I get key events in my panel before the textfield gets them (and maybe intercept them so that the textfield doesn't get them at all)?
    Background: the component is a self written table and the textfield is an editor. Now I have to make sure that when I am editing and press e.g. "cursor up", that not the textfield will get this key event but the table (which should traverse the current cell then ...)
    The problem is: I cannot change the textfield (extend it or something) because a possible solution has to work with any java awt "Component" (or at least with JComponent).
    Any help very appreciated.
    Michael

    Hello,
    implement the keyListener interface for the Extended component...
    and in Keypressed method
    keyPressed(keyEvent){
    // do all ur reuirements here
    //and comsume the keyEvent...
    hope this helps

  • How to catch key events in JWindow???

    Can somebody please suggest me how do I catch key events in a JWindow. I tried without success with addKeyListener( ) method. My sample code is attached below. I've j2sdk1.4.2_03 in my PC.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class EventCatcher extends JWindow implements KeyListener {
         public EventCatcher() {
              super();
              Container c = getContentPane();
              setBounds(100,100,400,400);
              c.setLayout(new FlowLayout());
              JButton button = new JButton("Hello");
              c.add(button);
    addKeyListener(this);
    requestFocus();
    setVisible(true);
         public void keyReleased(KeyEvent ke) {
    System.out.println("**************");
         public void keyPressed(KeyEvent ke) {}
         public void keyTyped(KeyEvent ke) {}
         public static void main(String str[]) {
              new EventCatcher();
    Regards,
    Koushik

    Hi GraemeHook!
    This is Khurram. I tried your code on my problem that is 95% like this problem but it could not be solved.
    can u please take view on my code.
    I m trying to move a frame that extends from JWindow on runtime with Key Board Arrow keys. but this only works when I extend this MainApp class from JFrame, but not when from JWindow.
    can u please help me. I also posted my own topic but no one response so found it resambling to my problem.
    hoping to hear from u soon
    you can also tell me at my email address
    [email protected]
    thanks
    ===========================================================
    MainApp.java
    *MainApp.java
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class MainApp extends JWindow {
      static LocationManager appLoc = new LocationManager();
      public MainApp() {
        try {
          jbInit();
        catch(Exception e) {
          e.printStackTrace();
      public static void main(String[] args) {
       MainApp frm = new MainApp();
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            int width = screenSize.width;
            int height = 45;
              frm.setFocusableWindowState(true);
            frm.setFocusable(true);
            frm.setSize(width, height);
            frm.setLocation(appLoc.setAppAtBottomCentered(width, height));
            frm.setLocation(appLoc.moveAppUpward(100));
            frm.setVisible(true);
      private void jbInit() throws Exception {
        this.getContentPane().setBackground(Color.white);
         addKeyListener(new java.awt.event.KeyAdapter(){
          int moveSpeed = 4;//must be even
          public void keyPressed(KeyEvent e){
            //JOptionPane.showMessageDialog(null,""+e.getKeyCode());
             if(e.getKeyCode() == KeyEvent.VK_SHIFT)
              if(moveSpeed==4)
                moveSpeed = 12;
              else
                moveSpeed = 4;
            if(e.getKeyCode() == KeyEvent.VK_UP)
              setLocation(appLoc.moveAppUpward(moveSpeed));
            else if(e.getKeyCode() == KeyEvent.VK_DOWN)
              setLocation(appLoc.moveAppDownward(moveSpeed));
            else if(e.getKeyCode() == KeyEvent.VK_LEFT)
              setLocation(appLoc.moveAppToLeft(moveSpeed));
            else if(e.getKeyCode() == KeyEvent.VK_RIGHT)
              setLocation(appLoc.moveAppToRight(moveSpeed));
            else if(e.getKeyCode() == 107) {//NUMPAD '+' Key For Vertically Increasing
              setSize(appLoc.increaseSize(0,moveSpeed));
              setLocation(appLoc.updateLocation());
            else if(e.getKeyCode() == 109) {//NUMPAD '-' Key For Vertically Decreasing
              setSize(appLoc.decreaseSize(0,moveSpeed));
              setLocation(appLoc.updateLocation());
            else if(e.getKeyCode() == 61) {// '+' Key For Horizontal Increasing
              setSize(appLoc.increaseSize(moveSpeed,0));
              setLocation(appLoc.updateLocation());
            else if(e.getKeyCode() == 45) {// '-' Key For Horizontal Decreasing
              setSize(appLoc.decreaseSize(moveSpeed,0));
              setLocation(appLoc.updateLocation());
    }====================================================================
    LocationManager.java
    * LocationManager.java
        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        import java.util.*;
        import java.sql.*;
    public class LocationManager {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        static Point newPoint = new Point();
        static Dimension newDim = new Dimension();
        static Dimension minDim = new Dimension();
        /** Creates a new instance of LocationManager */
        public LocationManager() {
        public LocationManager(int width, int height){
            this.setAppCenteredWithDim(width, height);
        public Point setAppCenteredWithDim(int width, int height){
            //Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          newDim.width = width;
          newDim.height = height;
            int sWidth = screenSize.width;
            int sHeight = screenSize.height;
            newPoint.x = (sWidth-width)/2;
            newPoint.y = (sHeight-height)/2;
            return newPoint;
            //return new Point(this.x, this.y);
        public Point setAppAtTopCentered(int width, int height){
            //Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          newDim.width = width;
          newDim.height = height;
            int sWidth = screenSize.width;
            int sHeight = screenSize.height;
            newPoint.x = (sWidth-width)/2;
            newPoint.y = 0;
            return newPoint;
            //return new Point(this.x, this.y);
        public Point setAppAtBottomCentered(int width, int height){
            //Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          newDim.width = width;
          newDim.height = height;
            int sWidth = screenSize.width;
            int sHeight = screenSize.height;
            newPoint.x = (sWidth-width)/2;
            newPoint.y = (sHeight-height);
            return newPoint;
            //return new Point(this.x, this.y);
        public Point setAppAtRightCentered(int width, int height){
            //Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          newDim.width = width;
          newDim.height = height;
            int sWidth = screenSize.width;
            int sHeight = screenSize.height;
            newPoint.x = 0;
            newPoint.y = (sHeight-height)/2;
            return newPoint;
            //return new Point(this.x, this.y);
        public Point setAppAtLeftCentered(int width, int height){
            //Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          newDim.width = width;
          newDim.height = height;
            int sWidth = screenSize.width;
            int sHeight = screenSize.height;
            newPoint.x = (sWidth-width);
            newPoint.y = (sHeight-height)/2;
            return newPoint;
            //return new Point(this.x, this.y);
        public Point moveAppUpward(int step){
            newPoint.y -= step;
            return newPoint;
            //return new Point(this.x, this.y);
        public Point moveAppDownward(int step){
            newPoint.y += step;
            return newPoint;
            //return new Point(this.x, this.y);
        public Point moveAppToLeft(int step){
            newPoint.x -= step;
            return newPoint;
            //return new Point(this.x, this.y);
        public Point moveAppToRight(int step){
            newPoint.x += step;
            return newPoint;
            //return new Point(this.x, this.y);
        public Dimension increaseSize(int w, int h){
          minDim.width = 116;
          minDim.height = 56;
          newDim.width += w;
          newDim.height +=h;
          if(w==0 && newDim.height > minDim.height)
            newPoint.y -= h/2;
          else if(newDim.width > minDim.width )
            newPoint.x -= w/2;
          return newDim;
        public Dimension decreaseSize(int w, int h){
          minDim.width = 116;
          minDim.height = 56;
          if(newDim.width > minDim.width )
            newDim.width -= w;
          if(newDim.height > minDim.height)
            newDim.height -= h;
          if(w==0 && newDim.height > minDim.height)
            newPoint.y += h/2;
          else if(newDim.width > minDim.width)
            newPoint.x += w/2;
          return newDim;
        public Point updateLocation(){
          return newPoint;
            //return new Point(this.x, this.y);
    }===================================================================

  • LoadMovie - How to block background events

    Hello,
    I use loadMovie to load a movie into a current movie clip,
    the movie is
    currently on the top, but how to block other objects/events
    so that only
    if this movie is closed, other can interact?
    I mean the loaded movie should be `modal`
    Thanks.

    Not sure if this is what you mean but basically you have a
    movie clip on top of other objects that can have mouse interaction
    in them. You want to prevent those objects from having mouse events
    happening when this current movie clip is on top of them.
    In as2 unless you can turn the visibility of everything in
    the back to 'false' you need to create a movieclip/button that
    act's like a click blocker. It will lie between the current
    movieclip and everything behind it.
    create movielclip called clickblocker and give it this code:
    clickBlocker.onRelease = function () : Void {};
    clickBlocker.useHandCursor = false;
    so basically it acts like a button that does nothing and
    prevents the mouse cursor from turning into a hand.

  • Blocking system keys

    I'm develpoing with NetBens4.1 / Windows CE 3.0 / JeodeJVM 1.2.
    I'd solved the Runtime.exec() lack in that JVM implementation by JNI calls to DLL's developed with Microsoft EVC++3.
    Somebody have's an C++ example on how to block system keys like CTRL+ESC, ALT+TAB in Windows CE ?
    Registry settings would help to...

    Found out.
    The taskbar get's the ALT+TAB and the CTRL+ESC events, so just disabling it locks these keys. Heres the JNI code:
    SysLib.cpp
    JNIEXPORT jint JNICALL Java_sys_SysLib_HideTaskBar
    (JNIEnv *env, jclass obj) {
    HWND hTaskBarWnd;
    HWND hDeskTopWnd;
    int rc=1;
    // find the window and hide
    hTaskBarWnd=FindWindow(_T("HHTaskBar"),NULL);
    if (hTaskBarWnd)
    EnableWindow(hTaskBarWnd,FALSE);
    ShowWindow(hTaskBarWnd,SW_HIDE);
    else
    rc= -1;
    // find the desktop window and resize it
    hDeskTopWnd=FindWindow(_T("DesktopExplorerWindow"),NULL);
    if (hDeskTopWnd)
    SetWindowPos(hDeskTopWnd,NULL,0,0,GetSystemMetrics(SM_CXSCREEN),
    GetSystemMetrics(SM_CYSCREEN), SWP_NOACTIVATE | SWP_NOZORDER |
    SWP_NOMOVE);
    else
    rc= -2;
    return rc;
    JNIEXPORT jint JNICALL Java_sys_SysLib_ShowTaskBar
    (JNIEnv *env, jclass obj) {
    HWND hTaskBarWnd;
    HWND hDeskTopWnd;
    int rc=1;
    // find the window and show it
    hTaskBarWnd=FindWindow(_T("HHTaskBar"),NULL);
    if (hTaskBarWnd)
    EnableWindow(hTaskBarWnd,TRUE);
    ShowWindow(hTaskBarWnd,SW_SHOW );
    else
    rc=-1;
    // find the desktop window and resize it
    hDeskTopWnd=FindWindow(_T("DesktopExplorerWindow"),NULL);
    if (hDeskTopWnd)
    SetWindowPos(hDeskTopWnd,NULL,0,0,GetSystemMetrics(SM_CXSCREEN),
    GetSystemMetrics(SM_CYSCREEN)-26, SWP_NOACTIVATE | SWP_NOZORDER |
    SWP_NOMOVE);
    // Note: 26 is the taskbar height it should be computed.
    else
    rc=-2;
    return rc;
    }

Maybe you are looking for

  • Remote app and iTunes 12

    My iTunes library no longer appears in my remote app.  I know it is not a Home Sharing issue because the library is linked to my Apple TV.  However, it won't appear in my remote app on my iPhone 6 or my iPad Air.  Hasn't worked since the update to iT

  • How to get Contract Account Number in Service Ticket

    Hi Experts, How to get Contract account number in Service Ticket, we are working in ISU environment. when i create the service ticket the contract account number is there in Business agreement number field in service tiket. Can anyone tell me how to

  • How to enable sound scrolling in After Effects?

    So basicly what im trying to do is be able to scroll through my compisition with the mouse and hear sound like in Sony Vegas is this possiple?  So if i drag my mouse over footage sound will play. Also can you enable keyframes on a mask? Thanks so muc

  • Can`t movies files into iTunes

    Hi, I am trying to move movies files into the iTunes library by dragging them and without success. I have tried to add the files with the file menu with the same results. Using iTunes 10.5 Can anyone help me with this? thanks, Amnon

  • Setting up my 5.6 NCB543W with my iMac over my wi-fi network

    Hi I just recieved my new   http://www.wansview.com/index.php/waterproof-ip-camera/661-ncb543w-to ad watchfull a watchful eye of my home and family when I am on the road touring. I am singer songwriter  http:/https://itunes.apple.com/us/album/a-love-