Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Beginning Java
What listener to implement for JList?
Bud Tippins
Ranch Hand
Posts: 52
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have the following code in NetBeans. On line #7 I'm getting the following error: "cannot find symbol - symbol: class ListSelectionListener" - question: what Listener should I have ListTest implement for a JList?
Thank you.
package listtest; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ListTest implements ListSelectionListener { String [] listEntries = {"alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta",}; JList list = new JList(listEntries); public static void main(String[] args) { ListTest lstTest = new ListTest(); lstTest.go(); } public void go() { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane scroller = new JScrollPane(list); scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panel.add(scroller); list.setVisibleRowCount(4); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addListSelectionListener(this); frame.getContentPane().add(BorderLayout.CENTER, panel); frame.getContentPane().add(BorderLayout.NORTH, list); frame.setSize(350, 300); frame.setVisible(true); } public void valueChanged(ListSelectionEvent lse) { if (!lse.getValueIsAdjusting()) { String selection = (String) list.getSelectedValue(); System.out.println(selection); } } }
Mohamed Sanaulla
Bartender
Posts: 3225
34
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ListSelectionListener is part of javax.swing.event package which you haven't imported in your
Java
code.
Mohamed Sanaulla |
My Blog
| Author of
Java 9 Cookbook
|
Java 11 Cookbook
Bud Tippins
Ranch Hand
Posts: 52
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you. That worked.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
help!!!a problem about java gui
A scrollable JList?
JList error
How to create a horizontal JList?
JRadioButtonList error
More...