Results 1 to 3 of 3
Thread: Two JLists
- 04-03-2012, 08:28 PM #1
Overboard!
- Join Date
- Apr 2012
- Location
- Manchester/Aberystwyth, UK
- Posts
- 4
- Rep Power
- 0
Two JLists
Hi, I'm a first year computer science student, working on my project Easter in my programming module. The idea of the project is to create a till machine for a pizza company.
I am trying to create two JLists, side by side. The first JList specifies the categories - pizza, drink, side - & the second list shows the products available in that category. The results of these two selections are then used & passed on to a method to add the product to the order, after hitting a JButton.
The problem is, the user cannot select a product on the second list, therefore the methods in the ListSelectionListener's valueChanged method don't get called for the second list. It's obvious that they do the for the first, as the product list displays the products.

The second list doesn't look properly selected.
My code:
The part in the constructor which does the lists:
Java Code:typeList=new JList(type); typeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane typeListScroller=new JScrollPane(typeList); typeList.addListSelectionListener(this); this.add(typeListScroller); productList=new JList(); productList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane productListScroller=new JScrollPane(productList); productList.addListSelectionListener(this); this.add(productListScroller);
The listener method:
Java Code:public void valueChanged(ListSelectionEvent e) { if(typeList.getSelectedIndex()==0){ productList.setListData(drinkList); if(productList.getSelectedIndex()==0){ System.out.println("Please work!") } } else if(typeList.getSelectedIndex()==1){ productList.setListData(pizzaList); } else if(typeList.getSelectedIndex()==2){ productList.setListData(sideList); } }
I'm just wondering if anyone has any idea on how to tackle the problem? I could do it a different way, but I quite like the way this looks [aesthetically].
- 04-03-2012, 09:50 PM #2
Re: Two JLists
Can you post a small program that compiles, executes and shows the problem? a SSCCE
If you don't understand my response, don't ignore it, ask a question.
- 04-03-2012, 09:57 PM #3
Similar Threads
-
JLists
By loopsnhoops in forum Advanced JavaReplies: 3Last Post: 05-28-2011, 12:22 AM -
JLISTS and Classes
By loopsnhoops in forum New To JavaReplies: 4Last Post: 05-27-2011, 07:54 AM -
JLists and JTables
By loopsnhoops in forum New To JavaReplies: 2Last Post: 05-27-2011, 01:19 AM -
Question about JLists
By Psyclone in forum AWT / SwingReplies: 4Last Post: 02-21-2010, 03:56 AM -
JLists - Filtering
By Psyclone in forum AWT / SwingReplies: 1Last Post: 02-16-2010, 06:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks