TreeSelectionListener() - one click two events!

Hi, I am working with a JTree, when I click a leaf node it fires two events and so the code handling the event runs twice (this is not a double click just clicking on the leaf node). Obviously this not what I want and I do not want to have to build a 'memory' into the associated classes as this seems a bit messy. I am still working to resolve this issue for myself and have 'googled it'. If I resolve the issue I will post back but any help gratefully received......
Trevor
The associated code I am using is shown below:
//instantiation of the Tree:
jTreeSubjects = new javax.swing.JTree(rootNode);
jTreeSubjects.setEditable(true);
//setting selection model and attatching the listener:   
jTreeSubjects.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        jTreeSubjects.setShowsRootHandles(true);
        jTreeSubjects.addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                jTreeSubjectsValueChanged(e);
//Handeling the events
private void jTreeSubjectsValueChanged(javax.swing.event.TreeSelectionEvent evt) {                                          
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeSubjects.getLastSelectedPathComponent();
        if (node == null){
            return;
        RegionTreeNode nodeInfo = (RegionTreeNode) node.getUserObject();
        if (node.isLeaf()){
            RegionTreeNode RegionTreeNodeSelected = nodeInfo;
            System.err.println(RegionTreeNodeSelected.file.getAbsoluteFile());
        } else {
            return;
}

Just to explain
I added the code shown using the post creation code feature in netbeans, Prior to this I had added a handler for event valuechanged (jTreeSubjectsValueChanged). Hence one component two listners.

Similar Messages

  • One Click - two times the same event?

    Hello guys, i have a little problem...
    When I click on my button it seems to be that the event handler method is run two times. I cant understand why - its happening at all buttons. can anyone help me?
    GUI.java
    public void actionPerformed(ActionEvent event) {
    transmit();                  // transmit the textfields
    p.translate();               // translate it to xml
    html = p.newHTML();          // translate the xml to html
    status.setText("<html>"+html);  // set the translatet html in the preview panel
    taHtml.setText(html);  // set the translatet html in the text area     
    The problem is that it appears two times in both, the area and the label.
    Here is the other code, if it helps.
    public String newHTML() {
              String tmp = xMLToHTMLParser.translate(xml);
              return tmp;
    public String translate(String delivered) {
                   xml = delivered;
                   html += "<b>";
                   try {
                   html += xml.substring(xml.indexOf("<Headline>")+10, xml.indexOf("</Headline>"));
                   catch(Exception e) {}  // When nothing is in the Headline do nothing.
    html += "</p>\n \n";
                   return html;
              }Thnak you so much for you help!
    Toby

    Ok, here is the transmit():
        /** Transmits the content of the Textfields to the Parser */
        private void transmit() {
             String Logoname = phases[phaseChoices.getSelectedIndex()];
             p.setLogoURL("http://www.destinations2discover.com/images/icons/"+Logoname);  // All icons are already saved on the Server
             p.setHeadline(tfHeadline.getText());
             // It's very tricky to get the correct dates in :)
             // First Step: transfer the correct Items, for next Step see Parser.java
             if( !tfAdditional.getText().equalsIgnoreCase("" )) {
                  try {
                       p.setDateline(tfAdditional.getText());
                  catch(Exception e) {
                  p.setDateline ("T Y P E C A S T   E R R O R   IN   D A T E L I N E   A D D I T I O N A L");
             /*else*/ if(( (!tfStartDay.getText().equalsIgnoreCase("")) &&  (!tfStartMonth.getText().equalsIgnoreCase("")) &&  (!tfStartYear.getText().equalsIgnoreCase("" )) && (!tfEndDay.getText().equalsIgnoreCase("")) &&  (!tfEndMonth.getText().equalsIgnoreCase("")) &&  (!tfEndYear.getText().equalsIgnoreCase("")) )) {
                  try {
                  p.setDateline ( Integer.parseInt(tfStartDay.getText()), Integer.parseInt(tfStartMonth.getText()), Integer.parseInt(tfStartYear.getText()), Integer.parseInt(tfEndDay.getText()), Integer.parseInt(tfEndMonth.getText()), Integer.parseInt(tfEndYear.getText()) );
              catch(Exception e) {
                   p.setDateline ("T Y P E C A S T   E R R O R   IN   D A T E L I N E   S T A R T  /  E N D");
             else if(((!tfStartDay.getText().equalsIgnoreCase("")) &&  (!tfStartMonth.getText().equalsIgnoreCase("")) &&  (!tfStartYear.getText().equalsIgnoreCase("" )) ) ){
                  try {
                       p.setDateline ( Integer.parseInt(tfStartDay.getText()), Integer.parseInt(tfStartMonth.getText()), Integer.parseInt(tfStartYear.getText()) );
              catch(Exception e) {
                   p.setDateline ("T Y P E C A S T   E R R O R   IN   D A T E L I N E   S T A R T");
    //-->FIX::  Add Annual Event Checkbox      if(!btnAnnual.getText().equalsIgnoreCase("StartDay"))
             if(!tfImageURL.getText().equalsIgnoreCase("")) {
                  p.setImageURL(tfImageURL.getText());
             if(!tfText.getText().equalsIgnoreCase("")) {
                  //p.setText(tfText.getText());
                  p.setText(taTxt.getText());
             if(!tfHyperlink.getText().equalsIgnoreCase("")) {
                  p.setHyperlinkURL(tfHyperlink.getText());
        }And here is the whole actionPerformed - just to make sure i have the listener not twice.
    public void actionPerformed(ActionEvent event) {
            if ("comboBoxChanged".equals(event.getActionCommand())) {
                //Update the icon to display the new phase.
                phaseIconLabel.setIcon(images[phaseChoices.getSelectedIndex()]);
            // Set the article ID from the radio buttons
            else if (event.getSource() == rbFOM) {
                p.setID(1);
            else if (event.getSource() == rbInsider){
                 p.setID(2);
            else if (event.getSource() == rbMustSee){
                 p.setID(3);
            else if (event.getSource() == rbMustDo){
                 p.setID(4);
            else if (event.getSource() == rbMustExperience){
                 p.setID(5);
            else if (event.getSource() == rbActivity){
                 p.setID(6);
            else if (event.getSource() == sendContent) {
                 transmit();                  // transmit the textfields
                 p.translate();               // translate it to xml
                 html = p.newHTML();          // translate the xml to html
                 status.setText("<html>"+html);  // set the translatet html in the preview panel
                 taHtml.setText(html);  // set the translatet html in the text area     
                 // write in html in line.html and xml in line.xml file
                 try  {
                 FileOutputStream fos = new FileOutputStream( "line.html" );
                fos.write( html.getBytes() );
                fos.close();
                catch ( Exception e ) { System.out.println(e); }
                xml = p.getXML();
                try  {
                 FileOutputStream fos2 = new FileOutputStream( "line.xml" );
                fos2.write( xml.getBytes() );
                fos2.close();
                catch ( Exception e ) { System.out.println(e); }
                show = true;     // workaround
            else if (event.getSource() == addContent) {
                 transmit();                  // transmit the textfields
                 p.translate();               // translate it to xml
                 html = p.newHTML();          // translate the xml to html
                 status.setText("<html>"+html);  // set the translatet html in the preview panel
                 taHtml.setText(html);  // set the translatet html in the text area     
                 // write in html in line.html and xml in line.xml file
                 try  {
                 FileOutputStream fos = new FileOutputStream( "line.html" );
                fos.write( html.getBytes() );
                fos.close();
                catch ( Exception e ) { System.out.println(e); }
                xml = p.getXML();
                try  {
                 FileOutputStream fos2 = new FileOutputStream( "line.xml" );
                fos2.write( xml.getBytes() );
                fos2.close();
                catch ( Exception e ) { System.out.println(e); }
                show = true;
            else if (event.getSource() == showInIE) {
                 if(show) {   // workaround
                 try  {
                      File fd= new File("");
                    path = fd.getAbsolutePath();
                    path = "C:\\Program Files\\Internet Explorer\\iexplore.exe "  + path +  "\\line.html";
                    System.out.println(path);  // debug
                      //     Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe \"C:\\Dokumente und Einstellungen\\intern\\Eigene Dateien\\code kopie\\text2XML\\text2Destination\\line.html\"");
                      Runtime.getRuntime().exec(path);
                 catch ( Exception e ) { System.out.println(e); }
                 show = false;   // workaround
                 showInIE.disable();
                 else if(show = false) {  // workaround
                      show = true;   // workaround
            }This problem is not only at the Button with "sendContent" it is also with "addContent' and "showInIE".
    Thank you two.

  • One Click Two Buttons

    Hi.
    I have a puzzle which I cannot appear to fix.
    I have a button on the stage which works fine and performs various actions.
    I have a movie clip on the stage, that contains 10 different buttons which when you click advances you to the next button and does different things and so on and so on. Again independantly this movie clip with buttons works fine.
    What I want to do however is this...
    I want to click on the main button on the stage, have that 'click' replicated to the other button within the movieclip so I can action both with a single clip.
    Any ideas please?
    Thanks

    This was a 250 frame movie clip with simple stop frames and code to move it on if it was pressed again within 25 frames (1 sec). If it was not pressed then it would go back to frame 1
    So frame one (stop)
    Frame 2-24 play another movie clip in mc11 and if pressed again advance frame 26
    Frame 25 stop and If not pressed return to frame 1
    Frame 26-49 play another movie clip mc11 and if pressed again advance frame 51
    Frame 50 stop and If not pressed return to frame 1
    and so on
    I have tried to replicate this by using on on press for each of the buttons in mc10 on frame 1 using a similar principle 
    eg:
    on (press) {
    Object(this._parent).mc11.gotoAndPlay(Yes_2);
    and
    on (press) {
    Object(this._parent).mc11.gotoAndPlay(Yes_3);
    and so on for each button but I am guessing this does not work because there is no press to action it.

  • Please help : two events on one button

    Hi there
    I set up a simple Flash banner with the following code to click through  to a web page:
    function buttonClickHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest("**URL**"));
    trace("You clicked me.");
    This worked fine, no problems.
    However, I was then asked to include a click counter by using this code:
    btn.buttonMode = true;
    btn.addEventListener(MouseEvent.CLICK, goOut);
    function goOut(e:Event){
    var url:String = root.loaderInfo.parameters.clickTag;
    var request:URLRequest = new URLRequest(**URL**);
    try {
    navigateToURL(request);
    catch (e:Error) {
    I've tried various ways to combine the two events, but it just doesn't  seem to work. I'm only used to one simple action at a time(!) and this  is needed urgently.
    Can anyone please help me resolve this problem? I will keep an eye on  the forum to update with any necessary info asked for.
    Many thanks in advance.

    You can just call two different functions by adding two listeners:
    btn.addEventListener(MouseEvent.CLICK, goOut);
    btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    If you want to combine them though, you do have one error - the goOut function needs to accept a MouseEvent, not a regular Event:
    function goOut(e:MouseEvent){
    Also, you shouldn't need the root when grabbing the FlashVar:
    var url:String = loaderInfo.parameters.clickTag;
    You should put a trace in there to make sure it's working as expected.
    And you didn't really say what isn't working. Do you get any errors?

  • My iMac locks up constantly in email. I click on one or two emails. Then when I click on another email, I get the spinning wheel and have to relaunch. Why does it get confused and lock up?

    My iMac locks up constantly in email. I click on one or two emails. Then when I click on another email, I get the spinning wheel and have to relaunch. Why does it get confused and lock up? Seems like it is stuck.

    10.6.8 here, MacBook Pro. Comcast. Mail  freeze ups. Occasional warnings to use "Log Out" under the Apple icon.
    Disk Repair run several times. Shows lots of Java  "remote" issues.
    I run Disk Repair several times, shows a lot of Java, "remote" issues.
    Restart don't know if it helps, I do it all the time. What's with quitting Mail but it doesn't quit, and why a separate maneuver to "Log Out".
    i

  • How do I add a desktop link to gmail?  I have one email account as my safari home page because it has trouble with apple mail, but I want a one-click link to two other email accounts.

    How do I add a desktop link to additional email accounts?  I have one email account as my safari home page because it has trouble with apple mail, but I want a one-click link on my desktop that takes me to two other email accounts.

    Can you set up a rule in your old account to forward mail to your new account and then delete it from the old account?
    (1012)

  • HT201406 The Home button on my iPod Touch is very unresopnsive.  It takes several tries to activate it.  While doing so, it responds to one click vs the intended two clicks and vice versa.  It is a very frustrating process.  Any suggestions?  I tried the

    The Home button on my iPod Touch is very unresponsive.  It takes several tries to activate it.  While doing so, it responds to one click versus the intended two clicks and vice versa.  It is a very frustrating process.  Any suggestions?  I already tried the "shut off" process that was suggested on the Apple site, but that did not help.

    Try:
    fix for Home button
    iPhone Home Button Not Working or Unresponsive? Try This Fix
    - If you have iOS 5 and later you can turn on Assistive Touch it add the Home and other buttons to the iPods screen. Settings>General>Accessibility>Assistive Touch
    - If not under warranty Apple will exchange your iPod for a refurbished one for:
    Apple - Support - iPod - Repair pricing
    You can do it an an Apple store by:
    Apple Retail Store - Genius Bar
    or sent it in to Apple. See:
    Apple - Support - iPod - Service FAQ
    - There are third-party places like the following that will repair the Home button. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens

  • Is it possible to add a shortcut to one or two very select websites to the navigational toolbar for convenient, one-click entry (i.e., which toolbar currently has buttons for viewing bookmarks and browsing history)?

    I would just like to be able to click once to get to one or two very important websites, just as I can now click once to show my viewing history (or scrapbook) in the sidebar.

    That's what the bookmarks toolbar is for.
    But putting single bookmarks there can fill it up quickly. Rather than a keyboard shortcut you can create a '''keyword shortcut''' for the bookmark, and that bookmark can be anywhere and out of sight. I keep all (most) of my keyword bookmarks in one folder on my bookmarks toolbar with the name beginning with the keyword. Here is an example, next door neighbor liked it for their netbook used at TV
    '''Name:''' tv: TV Listings - Find Local TV Shows and Movie Schedules - Listings Grid | TVGuide.com
    '''Location:''' http://www.tvguide.com/Listings/
    '''Keyword:''' tv:
    '''Description:''' PPP (User must be custom TV choices at Yahoo/TVGuide), start with zipcode (uncheck timezone), uses cookies, do for not logged in and for logged in. Must be logged in to pick your favorite channels to reduce list size.
    '''Firefox Keyword Shortcuts'''
    *http://dmcritchie.mvps.org/firefox/kws.htm
    Bookmarks toolbar styling'''
    * Stylish :: Add-ons for Firefox<br>https://addons.mozilla.org/en-US/firefox/addon/stylish/
    * '''Bookmarks Toolbar Fx4 Blue/Folders, Red/Bookmarks''' - Themes and Skins for Browser - userstyles.org<br>http://userstyles.org/styles/46947/bookmarks-toolbar-fx4-blue-folders-red-bookmarks

  • TS3274 Email display problem: My email only display the list of emails and a preview (first two lines of the body of the mail). If one click on the message it only shows the heading on the right hand side of the screen, but not the content.

    My email only display the list of mails in my in box with a preview of the first two lines of the body of the message. When one clicks on the message to open it, only the header is displayed in the right hand side of the screen - the actual message is missing. This happens on older mail previously downloaded that use to work properly as well. Any idea how to fix this?

    Try closing the Mail app completely and see if it works properly when you re-open the app : from the home screen (i.e. not with the Mail app 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Mail app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    If that doesn't work also do a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • I double-click on event  to see all the photos in that event displayed, but all I get is 1 large photo on the edit page.  To see the photos in that event, I have to scroll.  Need to be able to work with all the photos in that event, not one at a time.

    I double-click on event  to see all the photos in that event displayed, but all I get is 1 large photo on the edit page.  To see the photos in that event, I have to scroll.  Need to be able to work with all the photos in that event, not one at a time.

    Maybe you need to adjust the zoom slider in the lower left corner of the window?
    Regards
    Léonie

  • Two events getting trigered even though only one is being raised !

    I am creating a workflow for TRIP approval. In Start events I have added following two events :
    1. CREATED
    2. CHANGED
    Whenever a trip gets created or changed both the events get triggered thus two workflows start.
    I can customize my workflow for only one event but the issue is why two events are getting triggered ?

    Hi AD,
    not dealt with TRIP object,
    but the CHANGED event, is it created by you thru SWEC?
    If yes, check if the entry has OnChange and not Create.
    Hope it helps.
    Aditya

  • Why does it take two clicks to open an email now instead of one click it used to take?

    Heretofore, it took only one click to open an email in the inbox and now it takes 2 clicks. How do you get back to one click? Is there a setting or option for this?

    The standard has always been one click to show the message in the Message Pane and two clicks to open a message in a tab or window.
    If you do not have the Message Pane turned on press F8.

  • Since up date to Yosemite my iphoto 6000  pics are in chaos, 2011 pics mixed in 2014. Not always in event block sometimes just one or two?  Does anyone know how to put this right...help!

    Since upgrade to Yosemite my iphoto 6000+ pics are in chaos.  2011 mixed in with 2014 some in blocks, then many just random one or two pics. Event absolutely all over the place, over 5 years.  Can anyone help please? 

    Hello!
    See if you can solve this via the View-menu:

  • Need help to copy a photo between two events.

    I would appreciate it if someone could tell me how to copy a photo I want shown in two events. I have tried to duplicate the photo and drag it as well as cut and paste the duplicate, and in both instances, both photos move. Does iPhoto not allow the same photo in two events? When I click on the photo, the copy button is not highlighted as an option. Help?

    Duplicate the photo, flag one of them and go to the destination event and use the events menu ==> add flagged photo to selected event
    However this is not the best way to use iPhoto - events are a very basic inflexible organizing method - having photos in albums which uses no extra space is a much better way or organizing photos
    LN

  • Select or deselect multiple rows with one single selection  event

    Does anyone know how to create a JTable which can select or deselect multiple rows with one single selection event in JTable. Fore example, if the table has
    row1
    row2
    row3
    row4
    row5
    row6
    What I need is when user select row1 or row2, both row1 and row2 should be set to be selected. Then if user press CTRL and click one of row3 or row4, both of them should be selected including the previouse selected row1 and row2.
    For deselection, if row1 and row2 are selected, when users deselect one of row1 or row2, both of them should be deselected.
    Hopefully someone can give me a hint.

    Here is a partial solution using a JList. Only one line gets highlighted when the user makes a selection in the list. But, two lines are returned. There is a blank line between every two lines.
         private void addLineToList() {
              String a = f_one.getText();
              String b = f_two.getText();
              if (a.length() == 0) {
                   Utils.showInformationMessage("Item field is empty.");
                   f_one.requestFocusInWindow();
                   return;
              if (b.length() == 0) {
                   Utils.showInformationMessage("Match field is empty.");
                   f_two.requestFocusInWindow();
                   return;
              model.addElement("item: " + a);
              model.addElement("match: " + b);
              model.addElement(" ");
              int size = model.getSize();
              pairList.setSelectedIndex(size - 3);
              f_one.setText("");
              f_two.setText("");
              f_one.requestFocusInWindow();
         private void editList() {
              if (pairList.getSelectedValue().toString().equalsIgnoreCase(" ")) {
                   Toolkit.getDefaultToolkit().beep();
                   f_one.requestFocusInWindow();
                   return;
              if (!f_one.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Item field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   OptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              if (!f_two.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Match field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   JOptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              String item = "";
              String match = "";
              int index = pairList.getSelectedIndex();
              String choice = model.getElementAt(index).toString();
              if (choice.startsWith("item")) {
                   item = choice;
                   match = model.getElementAt(index + 1).toString();
                   model.remove(index);
                   model.remove(index);
                   model.remove(index);
              else {
                   item = model.getElementAt(index - 1).toString();
                   match = choice;
                   model.remove(index + 1);
                   model.remove(index);
                   model.remove(index - 1);
              int size = model.getSize();
              if (size > 2) {
                   pairList.setSelectedIndex(size - 2);
              f_one.setText(item.substring(6));
              f_two.setText(match.substring(7));
              f_one.requestFocusInWindow();
         }

Maybe you are looking for

  • Create material Master by connecting SAP Tables to SQL server tables

    We would like to use data in SQL server tables to upload material master into ECC. We have a number of rules embedded into the SQL server tables and would like that the LSMW program should pick up records directly from the SQL table without passing t

  • Specified Sort Order not working correctly in InfoView

    Hello All, We are running Crystal 2008 version 12.2.0.290 with Infoview 12.1.0 and are having a problem with specified sort orders working correctly.  In Crystal we are using the 'Chart Expert' to set the specified order of the percent bar chart.  It

  • Problem with MB1C

    Hi ,                    When i was trying to post some inventory in the system, i was getting an error that closing period is between 07/2003 and 08/2003.I went to MMPV and opened the period for 06/2007.But the system is saying that it is not valid p

  • IMac 21" Display square artefacts problem

    Hello everyone! I've already seen that there are several people having same problems (or almost the same), but i assume not quite the same. Problem is - yesterday while watching just a film suddenly I saw strange colored squares all over my 21" iMacs

  • How do i resolve error (-50) i cannot download a rental

    I rented a movie from i tunes. it stopped loading on its own and everytime i attempt to restart an error window pops up, an unknow error occured (-50). i would like to know how to fix this or get my money back