Adding an ActionListener to JLists *AAH*
Author |
Message |
Aziz

|
Posted: Fri Sep 02, 2005 9:00 am Post subject: Adding an ActionListener to JLists *AAH* |
|
|
Everything was running smoothly until I ran into this problem....I want some buttons to be enabled (Open/Rename/Delete) when a user selects a list from the JList, but it doesn't have an addActionListener method, neither does DefautListModel...any help? Please? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Aziz

|
Posted: Fri Sep 02, 2005 10:29 am Post subject: (No subject) |
|
|
Never mind, figured it out. For anyone else though, this works fine:
Make sure you include this line too:
Java: | import javax.event.*;
|
Java: | //Add selection listener to check an item is selected
list. addListSelectionListener(
new ListSelectionListener()
{
public void valueChanged (ListSelectionEvent e )
{
if (list. getSelectedIndex() == - 1) //Nothing is selected
{
//Disable buttons
enableButtons (false);
}
else //Something is selected
{
//Enable buttons
enableButtons (true);
}
}
}
);
|
|
|
|
|
|
 |
|
|