Forums Register Login
Swing listSelectionListener communication
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 ( "http://AccessibleSailing.info
photoLabel =
new JLabel(new ImageIcon(photoURL,"ragamuffin") );
catch(java.net.MalformedURLException 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.
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
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

This thread has been viewed 840 times.

All times above are in ranch (not your local) time.
The current ranch time is
Mar 20, 2018 07:52:59.