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

3
Hi,
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,

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

kind regards,

Jos
May 7 '09 #2
dvjava
3
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
JosAH
11,448 Expert 8TB
Try to set the selection mode:

Expand|Select|Wrap|Line Numbers
  1. JList yourList ...;
  2.  
  3. yourList.setSelectionMode(
  4. ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  5.  
kind regards,

Jos
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
Nepomuk
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.