Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8124669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:32:04+00:00 2026-06-06T06:32:04+00:00

When making a selection on this simple gui list I am getting valueChanged to

  • 0

When making a selection on this simple gui list I am getting valueChanged to execute twice once when mouse down and once when mouse up.

import groovy.swing.SwingBuilder
import java.awt.*
import java.swing.*
import javax.swing.*


def main(){
    new SwingBuilder().edt {
        frame(title:'Testing', pack:true, show:true) {
            vbox {
                panel(){
                    textbox = label(text:'null')
                }
                panel(){
                    listing = list(valueChanged:{
                            mess(listing.selectedValue);// this code runs twice
                        },
                        listData: ['test','another','test','and','again'])
                }
            }
        }
    }
}

def mess(mytext){
    new SwingBuilder().edt {
        frame(title:'Message', pack:true, show:true){
            vbox {
                panel(){
                    label(text:mytext)
                }
            }
        }
    }
}

main();

I have looked for other questions similar to this one on stackoverflow to no avail if it is a duplicate I’m sorry and I will remove it but I don’t believe it is. All I’m trying to do it get this to not execute on mouse up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:32:05+00:00Added an answer on June 6, 2026 at 6:32 am

    Yes, with a Swing JList you get two valueChanged events when the user clicks on a row.

    The first click will have event.valueIsAdjusting == true to indicate the user is in the process of changing the value, and the second event will have event.valueIsAdjusting == false to show the selection has been made (see the evaluation section of this bug report* here and the event documentation here)

    Changing:

     valueChanged:{
       mess(listing.selectedValue);// this code runs twice
     }
    

    To:

     valueChanged:{ event ->
       if( !event.valueIsAdjusting ) mess(listing.selectedValue)
     }
    

    Should fix this…

    (* It should be noted that this is not a bug, as can be seen by it’s closure status) 🙂


    edit

    To clear the selection, you can change main() to:

    def main() {
      def data = ['test','another','test','and','again']
      def codeFired = false
      new SwingBuilder().edt {
        frame(title:'Testing', pack:true, show:true) {
          vbox {
            panel(){
              textbox = label(text:'null')
            }
            panel(){
              listing = list listData: data, valueChanged: { event ->
                if( !event.valueIsAdjusting && !codeFired ) {
                  mess( listing.selectedValue )
                  codeFired = true
                  listing.clearSelection()
                  codeFired = false
                }
              }
            }
          }
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making a drop down list for my JSP and the values I'm entering won't
I'm making a simple program in Java. Given a set of letters it'll list
This is similar to my last question. I'm making a simple tcp/ip chat program
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
Context: I'm making a simple solar system simulation in c++/OpenGL. Research: I've tried searching
I am new to C++ and am making a simple text RPG, anyway, The
This seems like a very simple problem, but I cannot get a scrollbox to
Background: For one of my university courses, I am making Chess. The GUI is
I'v been making a simple target card reading server on eclipse, on my mac
Apple has a nice little tutorial for making a simple master-detail interface. Interface Builder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.