Action Listener on a List

Posted on 2003-03-24
Medium Priority
Last Modified: 2010-03-31
What I am trying to do is to have a button on my GUI interface that will delete a selected item in my list. Do i need to have an actionListener on my List and Button?
So I want my "Remove" button to remove the seleted item, in my List(toRecord)
Here is my code

Label record = new Label("RECORD LIST");
record.setBounds(20, 400, 170, 20);
toRecord = new List(5,true);
toRecord .setBounds(20, 420, 600, 130);

Button removeButton = new Button("Remove");
removeButton.setBounds(20, 550, 50, 20);
removeButton.setBackground(Color.yellow) ;

then in actionPerformed:-

    if (buttonName.equals("Remove"))

//? Dont know how to implement this

Question by:chocobogo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 15

Expert Comment

ID: 8195115
if (buttonName.equals("Remove"))


LVL 15

Accepted Solution

ozymandias earned 200 total points
ID: 8195123
You only need a listener on the button.
When button is pressed you remove the selected item from the list as shown above.

NB : You may need to check that an item in the list is actually selected first.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question