471,853 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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 4190
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
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.