TreeSelectionListener detect if mouse click

hi,
i've got a JTree and I'm using a TreeSelectionListener to carry out different actions when the user clicks on nodes. however, sometimes i want to change the selection on the tree programmatically (i know how to do this bit), and for the action associated with clicking on the node not to happen.
is it possible within the valueChanged method of the TreeSelectionListener to determine if the selection was changed by a mouse click or programmatically? or can anyone think of another way to approach this?
cheers for any help!

You can't do that with the event, but if you create a boolean variable named for example
boolean programSelection = false;
and when you change the selection programmatically you put the value to true. In the method valueChanged you have to test the value of programSelection like that :
public void valueChanged(ChangeEvent e) {
   if (programSelection) {
      // the code when the selection come from the program
     programSelection = false;
   else {
      // the code when the selection come from the user
}

Similar Messages

  • Detecting missing mouse clicks?

    There are some times when a user clicks on a movie clip in my
    SWF that the mouse click goes undetected by any of my mouse event
    handlers.
    I even added a MouseClick listener at the root sprite of my
    SWF.
    Is there any way to detect where this mouse click is going,
    and why it is not being detected by anything?
    NOTE: I have *only* seen this happen so far when a user
    clicks on a movie clip that I have dynamically loaded. The movie
    clip is not playing, and I am manually calling gotoAndStop() on the
    movie clip various times. Not sure if that is related.

    please don't cross post.

  • Detecting a mouse click on any (all) child components...

    Hey All,
    I am writing a number of compound GUI elements that i want to make focusable when you click any part of them. (i.e. a JTextArea inside a JScrollPane, coupled to a JTextField to provide input to the JTextArea).
    Is there an easy way to detect mouse clicks on child components of a JPanel?
    My current code is:
    m_oInputBox.addMouseListener(this);
    m_oOutputBox.addMouseListener(this);
    m_oScrollPane.getVerticalScrollBar().addMouseListener(this);
    This detects most of the mouse clicks, but not those on the buttons that form the scroll bar ends or the scroll bar slider when it is present.
    Any way tou can detect clicks on these too??
    Iso

    P.S. It does actually detect clicks on the scroll bar slider - just not onthe buttons that form the slider end caps (up/down).
    Iso

  • Detect when mouse clicked over desktop

    hello guys,
    i have a graduation project working with networking, the instructor on the server side presents a powerpoint slide show an when he moves to the next slide, i have to send an order to the students (clients) to move to the next slide.
    can it be done???? plz if there is an example for both; the sender and receiver help me with it.
    tahnk you very much.

    http://forums.devshed.com/t311756/s.html
    http://forums.devshed.com/t311567/s.html
    http://forums.devshed.com/t311568/s.html

  • Mouse clicking

    Hi all!
    Maybe it's too easy question, but I really appreciate your help!
    What listener should I use if I want to detect every mouse click
    wherever on the screen? When I add MouseListener to any Component,
    the MouseListener method mouseClicked is called only if I clicked
    on that component!
    many thanks

    What listener should I use if I want to detect every
    mouse click
    wherever on the screen?A native one.

  • Mouse clicks not detected on JTabbedPane

    Hi all,
    I have a JPanel placed inside a JTabbedPane. I want to double-click on the JPanel and bring up a JDialog. This works fine if the JPanel is not in a JTabbedPane, but if it is on a JTabbedPane, then the mouse clicks are not detected. I'd greatly appreciate any help you can give me.

    Here is a sample program that seems to work:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class TestInternalFrame extends JFrame
         public TestInternalFrame()
              JDesktopPane desktop = new JDesktopPane();
              setContentPane( desktop );
              JInternalFrame internal = new JInternalFrame( "Internal Frame" );
              desktop.add( internal );
              internal.setLocation( 50, 50 );
              internal.setSize( 300, 300 );
              internal.setVisible( true );
              JTabbedPane tabbedPane = new JTabbedPane();
              internal.getContentPane().add(tabbedPane);
              tabbedPane.setPreferredSize( new Dimension(300, 200) );
              JPanel panel = new JPanel();
              tabbedPane.add( "Empty Panel", panel );
              panel.addMouseListener( new MouseAdapter()
                   public void mouseClicked(MouseEvent e)
                        System.out.println(e.getClickCount());
         public static void main(String args[])
    TestInternalFrame frame = new TestInternalFrame();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.setSize(400, 400);
    frame.setVisible(true);

  • Detect mouse clicks or keyboard events on desktop or everywhere

    Hi,
    What I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left mouse click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked and then take the screenshot.
    What I don't know how to do is to detect the mouse and keyboard events when the application is supposed to be running minimized in the system tray.
    How can I do that? Can anybody give me a hint?
    Thanks in advance.

    It's not possible with plain Java. You will need native code for this. Take a look at JNA.

  • Detecting mouse clicks in editable cell of JTable

    Hi everyone :)
    I thought that this question might have been asked before, but I have searched the forums extensively and have not been able to find the solution.
    What I want to achieve is to detect single and double mouse clicks on JTable cells (that are editable).
    For example, I have a JTable and there exists within it an editable cell. If the user clicks on it once then that cell goes into edit mode, and the user can type directly into the cell. I have already successfully implemented this.
    However, what I also want to do is detect a double-click so that I can pop up a dilaog that shows a list of default values that the user can select.
    So here is what I want;
    1. User clicks on the cell once.
    2. Cell moves into edit mode.
    3. If the user clicks again within a certain time interval then cancel edit mode and pop up a dialog containing values that the user can select from.
    I think that to do this I need to be able to detect mouse clicks on the cell that is currently being edited. So far I have been unable to discover how this is done. I have even tried extending JTextField to get what I want, but with no luck.
    Any help would be greatly appreciated.
    Kind regards,
    Ben Deany

    Thanks for the reply.
    Unfortunately, it is not possible to call 'AddMouseListener()' on a cell editor. You are only able to call 'addCellEditorListener()' and that only allows two events to the broadcast (edit cancel, and edit stop).
    Ben

  • How to detect mouse clicks on desktop?

    Hi All,
    I need to detect mouse clicks on the desktop and find out mouse position on the screen. How to listen to mouse events if I don't have any swing components like containers, panels, windows, etc? All things like "addMouseListener" are supposed to be with such components. But my program is running in the background and it doesn't have any graphical interfaces. So, I need to detect if a mouse button is pressed at any position on the screen.
    Thanks for any help!

    Why? What program feature do you intend to offer, by knowing what a user clicks on (besides the application itself).Hi, well what I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked, once done, I have to take an screenshot...so on.
    How can I do that? Can anybody give me a hint? Thanks in advance.

  • How to detect mouse click event?

    Hello,
    I would like to have a vi to detect left, right and no mouse click. I mean that in the vi attached, Button2 should be 0 (no click), 1 (left c.) or 2 (right c.) depending on the event occured in i-1. cycle. My vi is the modyfied version of the one found here:
    http://www.ni.com/example/27663/en/
    Sometimes it works fine, but another time nothing happens when I click.
    I think the main problem is with the execution times at the for loop and event structure.
    Could you help me how to deal with the problem?
    Thanks you!
    Attachments:
    mouse1.vi ‏12 KB

    Hi VampireEmpire,
    Your For loop iterates twice. If an event occures during first iteration everything is fine - Button 2 refreshes during second iteration. But what happens when an event occures during second iteration? Does Button 2 have a possibility to refresh? 
    1. Do you see the problem now?
    2. And if you do - do you really need For loop? I would suggest you trying removing it and connecting shift register to the while loop.
    Bluesheep

  • Detecting mouse click on a line

    I'm learning making GUI apps in Java.
    Here is my problem. Suppose I draw a line on a JPanel. If I want to find out if the line is clicked or not, what is the best way to do it?
    I did some research, looked at API. If I suppose my line is Line2D, then since its a line it doesn't have an area, so its contains method always returns false (..from API). So i dig around some more and came up with the solution of getting the shape from the stroke and calling its contains method.
    This is a code for what i mean..
    private Line2D.Double testLine;
    //mouse clicked event
    public void mouseClicked(MouseEvent e) {
            int x = e.getX();
            int y = e.getY();
            BasicStroke stroke = new BasicStroke(4);
            Shape testShape = stroke.createStrokedShape(testLine);
            if(testShape.contains(x,y)){
                System.out.println("this will be printed if clicked on line");
        }Well, the above solution works fine.
    Is it the right way of doing it or is there a better way around for this?
    Any help will be appreciated.
    Thanks.

    When trying to test if a line was pressed I usually test if the distance between the mouse coordinates and the line is smaller than some constant (usually 5 pixels).
    For this you have to write your own code to calculate the distance between a point and a line.

  • Detect mouse click in FlashPlayer ActiveX

    I'm hosting the FlashPlayer ActiveX control (Flash9f.ocx) in
    a VB 6 application. The OCX exposes the following events:
    FlashCall, OnProgress, OnReadyStateChange and FSCommand. It does
    not expose the traditional Click, MouseUp or MouseDown events (for
    example) so is there a way to receive mouse click events in the
    hosted application?
    Also, I am unable to find any documentation on the FlashCall
    event. Any ideas what it is and how it works?
    Thanks to any and all.

    jList1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jList1_mouseClicked(e);
    public void jList1_mouseClicked(MouseEvent e){
    JOptionPane.showMessageDialog(null,"test"); }
    I got it. Thanks.
    I forgot to add the MouseListener initally

  • Mouse Clicks/Positons in Pictures!

    Even a guru learns new things...
    I just discovered the use of a picture control/indicator to detect mouse positions and clicks! What a wonderful thing. I have LabVIEW 6.0.2, and have, up to now, not known about this. To all those out there who I recommended to use the mouse click API for Windows, I apologize. This is such a marvelous way to get Mouse information. It's easy, efficient, and completely held within LabVIEW.
    If anyone is wondering what I am talking about, go to Help>Examples in LabVIEW and go to the Examples>Advanced Examples>Picture Control Examples>Mouse Control.vi to see what I mean. I didn't realize that if you dropped a picture control (even as an invisible object!) on the front panel that you could use prop
    erty nodes to get x and y positions, and also the left, right, shift left or right, and third mouse button click information.
    Of course, I hear that this may all be somewhat obsolete in LabVIEW 6.1, but for those still using 6.01 or earlier, it's a great tool that means you don't have to mess with API, MFC or dlls.
    Any comments or questions?

    Hi,
    This is ideal for some applications, you can even build drag/drop functions
    into a picture control using this. But there are some backdraws (or one very
    big one);
    The picture control needs to be the control on front.
    The picture control needs to cover the entire area you need information on.
    This implies that normal functions of controls and indicators cannot be
    used, not even simply clicking on a button...
    It also makes the screen updates take a lot more proccessor time, because
    controls/indicators are overlapping. In the example for instance, the charts
    are not clear to read, because they're flickering.
    Regards,
    Wiebe.
    "Labviewguru" wrote in message
    news:[email protected]..
    > Even a guru learns new things..
    >
    > I just discovered the use of a picture control/indicator to detect
    > mouse positions and clicks! What a wonderful thing. I have LabVIEW
    > 6.0.2, and have, up to now, not known about this. To all those out
    > there who I recommended to use the mouse click API for Windows, I
    > apologize. This is such a marvelous way to get Mouse information.
    > It's easy, efficient, and completely held within LabVIEW.
    >
    > If anyone is wondering what I am talking about, go to Help>Examples in
    > LabVIEW and go to the Examples>Advanced Examples>Picture Control
    > Examples>Mouse Control.vi to see what I mean. I didn't realize that
    > if you dropped a picture control (even as an invisible object!) on the
    > front panel that you could use property nodes to get x and y
    > positions, and also the left, right, shift left or right, and third
    > mouse button click information.
    >
    > Of course, I hear that this may all be somewhat obsolete in LabVIEW
    > 6.1, but for those still using 6.01 or earlier, it's a great t
    ool that
    > means you don't have to mess with API, MFC or dlls.
    >
    > Any comments or questions?

  • Incorrect detection of double-clicks in layers and channels windows. (Mac OS X 10.6.8)

    Photoshop will detect a double-click in the layers and channels panels even when there are different modifier keys held down on the first click vs. the second click.
    I have never intended to double-click and accidentally changed the modifiers I was holding down between clicks.  I often perform an action requiring modifier keys and immediately follow it with an action that requires no modifiers (or different modifiers).
    I realize that the conventions for what constitutes a double-click are platform dependent and not particularly well documented, but I do expect Photoshop to work the way that my operating system does (Mac OS X 10.6.8)).  I know older versions of Windows detected double-clicks even when modifiers were changed between clicks, but I believe the latest versions behave similarly to OS X.
    Examples:
    Start by having a document open with multiple alpha channels and layers in it.
    Select an alpha channel by clicking on it's thumbnail in the channels panel.
    Quickly hold down the control key and click again.
    Result: this brings up the "Channel Options" window. (as if you had double-clicked)
    Expected result: should bring up the channel's contextual menu.
    Bonus extra nitpick:  The window opened on mouse-down, not on mouse-up.
    Create a non-blank alpha channel.
    Hold down the command key and click on that alpha channel's thumbnail. (loads the channel into the selection)
    Quickly release the command key and press the mouse button.
    Result: Brings up the "Channel Options" window. (as if you had double-clicked)
    Expected result: Start a drag operation on the channel.
    Click on a layer in the layers panel to select it.
    Move the mouse pointer to a different layer.
    Hold down the shift key and click to select multiple layers.
    Quickly release the shift key and press the mouse button.
    Result: Brings up the "Layer Style" window.  (as if you had double-clicked)
    Expected result: Begin a drag operation.
    Bonus extra nitpick:  The window opened on mouse-down, not on mouse-up.
    Interestingly the layers panel does the correct thing when control is pressed between clicks, but the channels panel does not.
    The options windows opening on mouse-down instead of mouse-up has never bothered me, but I believe it goes against convention.
    Thanks.

    Very detailed report, Jay. I was able to see exactly what you're talking about, and reproduce this using my trackpad. I'm wondering if this is an OS issue, or something that can be tweaked in Photoshop. Even with files in Finder, you can activate a double-click even with a slight hesitation, which is similar to the behavior in Photoshop.

  • Z8000 mouse click behaviour is not consistent

    The mouse is very elegant and practical for the type of business , I just have this weired behaviour on my Tecra Z50-A Windows 8.1 , the problem is , the mouse Left click is switching to right-click after few clicks, if I take my hand off the mouse and try again, the Left click comes back to normal and so on, after few clicks the click switches to Right-click until i take my fingers out of the mouse and put them back!
    The HP product solution finder didnt detect my mouse, I believe due to not supported product (then why it is in the product support page????)
    Any help or guidance here is much appreciated!
    thanks.

    @lolotimo 
    ‎Thank you for using HP Support Forum. I have brought your issue to the appropriate team within HP. They will likely request information from you in order to look up your case details or product serial number. Please look for a private message from an identified HP contact. Additionally, keep in mind not to publicly post ( serial numbers and case details).
    If you are unfamiliar with the Forum's private messaging please click here to learn more.
    Thank you,
    Omar
    I Work for HP

Maybe you are looking for

  • Unable to launch Java Swing application with JSE 5.0

    Hi, we have a swing appln that gets downloaded via java webstart - which was working fine with 1.4.x until 5.0 came. I know that JSE 5.0 includes java webstart too - but when I start my application, I get Marshal error & filenotfound Exception. What

  • TS2972 Why can I not open iTunes on my laptop?

    I have been trying to open up iTunes on my laptop. I have Windows 7, and I have tried Repairing iTunes and I have uninstalled and reinstalled iTunes. Can anyone help me? This is so frustrating. Thank you very much!

  • Handle special characters in org name

    Hi, I need to do a org recon from my Directory server. Some of the org names have the '/' character and OIM says it can't create the org because of the special character. Could someone please tell me how do I handle this. Thanks, Supreetha

  • Debug from one machine not working , why ?

    I created standard debug configuration for portal: remove java application type ... , and it works immediately after portal is restarted, (connecting fast). but after disconnect and try to run debug again, studio againg newer complete step "establish

  • DI al_engine Process keeps running after completion of job

    We have DI installed on Unix. We have been noticing multiple al_engine processes in active status even when there are no DI jobs running. In order to get rid of these processes, we have been periodically bouncing the server. Is there a cleaner way of