Results 1 to 5 of 5
Thread: Question about JLists
- 02-21-2010, 02:41 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 81
- Rep Power
- 0
Question about JLists
I have 2 JLists in the same GUI with 3 ComboBoxes and a bunch of Radio Buttons. I have the radio buttons grouped together.
In the GUI, when I selected an item from a ComboBox or RadioButton (which highlights it) and then select another component, the ComboBox/RadioButton item becomes unselected.
Whenever I choose an item from a JList and then click on a radio button, combo box, or another list... the item remains highlighted. Is there a way to have the selected item in the list become unselected (unhighlighted) when I click on another component?Last edited by Psyclone; 02-21-2010 at 03:01 AM.
- 02-21-2010, 03:01 AM #2
Member
- Join Date
- Jan 2010
- Posts
- 81
- Rep Power
- 0
Sorry, forgot to mention, I have tried using list.clearSelection(). But whenever I do this, the first list i click on gets selected normally. When I choose an item from the opposite list, it just outlines the selection (doesn't highlight it). If I click a 2nd time (on any item from the list) it becomes highlighted like normal. Then the problem just reverses and I must click on the other list twice to get an item to work.
This does not occur when I don't use clearSelection(), but the item from the opposing list remains highlighted at all times.
- 02-21-2010, 03:33 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
one way might be to add a class field
int selectedIndex = -1;
then add a focusListener to the JList (list)
Java Code:list.addFocusListener(new FocusListener(){ public void focusGained(FocusEvent fe){ list.setSelectedIndex(selectedIndex); } public void focusLost(FocusEvent fe){ selectedIndex = list.getSelectedIndex(); list.clearSelection(); } })
- 02-21-2010, 03:51 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 81
- Rep Power
- 0
Thanks, I got it to work, but I had to use...
The way you had it was fine except that it selected the last known index when the list became focused instead of the item clicked.Java Code:list.addFocusListener(new FocusListener(){ public void focusGained(FocusEvent fe){ list.setSelectedIndex(list.getSelectedIndex()); } public void focusLost(FocusEvent fe){ list.clearSelection(); } });
THANKS!
-
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
JLists - Filtering
By Psyclone in forum AWT / SwingReplies: 1Last Post: 02-16-2010, 06:09 AM -
question
By ayoood in forum Java SoftwareReplies: 6Last Post: 07-07-2008, 01:32 PM -
a question
By slytheman in forum Java ServletReplies: 0Last Post: 03-12-2008, 04:11 AM -
Need help with a question please
By sonal in forum New To JavaReplies: 1Last Post: 11-29-2007, 09:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks