469,282 Members | 2,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

JList highlighed stay on previously selected item

I am wondering if there is way to twist JList such that the highlight still remains on previously selected item after other item is selected.
For example, this list has 4 items: A, B, C, D
If I select A, A will be highlighted.
I then select C, C will be highlighted and A still remains highlighted as well.
I then re-select A again, A now becomes "de-highlighted".

Thanks in advance,

May 6 '09 #1
3 4028
11,448 Expert 8TB
Doesn't one of the selection modes, using the setSelectionMode( ... ) method help you?

kind regards,

May 7 '09 #2
Can you be more specific, JosAH?
I tried the below code borrowed from Hans Muller, Sun java website, and it makes item being toggle only but does not keep 2 items highlighted.

JList list = new JList(MyArray);
list.setSelectionModel(new ToggleSelectionModel());

class ToggleSelectionModel extends DefaultListSelectionModel
public void setSelectionInterval(int index0, int index1) {
if (isSelectedIndex(index0)) {
super.removeSelectionInterval(index0, index1);
else {
super.setSelectionInterval(index0, index1);
May 7 '09 #3
11,448 Expert 8TB
Try to set the selection mode:

Expand|Select|Wrap|Line Numbers
  1. JList yourList ...;
  3. yourList.setSelectionMode(
kind regards,

May 7 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Roman Thurnherr | last post: by
4 posts views Thread by Nepomuk | last post: by
8 posts views Thread by sukatoa | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.