aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Swing listSelectionListener communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing listSelectionListener communication" Watch "Swing listSelectionListener communication" New topic

Swing listSelectionListener communication

John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 183
I have a Swing applet which has a JList in a JScrollPane. I did a jlist.addListSelectionListener and passed it the constructor for an anonymous inner class. In this inner class listener, I want to modify the content of a JLabel which has already been added to the content pane. The JLabel was constructed with an ImageIcon
JLabelphotoLabel= new JLabel();
URL photoURL = new URL ( "
photoLabel =
new JLabel(new ImageIcon(photoURL,"ragamuffin") );
catch( me)

The listener inner class gets a selection which is in effect a user's selection of a different photo for the JLabel. How can I accomplish this? Naturally, the inner class is not allowed access to a local variable outside of its scope.
Jagan Mohan Reddy

Joined: May 15, 2001
Posts: 18
Make the label to be a final variable...

final JLabel label = new JLabel(new ImageIcon(URL,"Icon"));
In the inner class use
label.setIcon(new ImageIcon(URL,"Icon1"));

hope this mighr solve ur problem..
Jagan Mohan Reddy
I agree. Here's the link:
subject: Swing listSelectionListener communication
Similar Threads
Help building a JAR file...
Retrieving components inserted into a JTextPane
Creating a JAR file: File finding problem
Mouse shift event coding - to trigger a predetermined sequence of images to a GUI
Problem in Image Loading in Swing Applet