Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Adding an ActionListener to JLists *AAH*
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aziz




PostPosted: 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
Sponsor
sponsor
Aziz




PostPosted: 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);
                        }
                }
        }
);
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: