• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Action Listener on a List

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");
add(record);
record.setBounds(20, 400, 170, 20);
toRecord = new List(5,true);
toRecord .setBounds(20, 420, 600, 130);
add(toRecord);

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


then in actionPerformed:-

    if (buttonName.equals("Remove"))
    {

//? Dont know how to implement this
}

0
chocobogo
Asked:
chocobogo
  • 2
1 Solution
 
ozymandiasCommented:
if (buttonName.equals("Remove"))
   {

        roRecord.remove(toRecord.getSelectedIndex());

   }
0
 
ozymandiasCommented:
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now