java - How to set multiple items as selected in JList using setSelectedValue? -
i have jlist populated dynamically adding underlying listmodel. if have 3 strings value know , do
for(i=0;i<3;i++){ jlist.setselectedvalue(obj[i],true);//true shouldscroll or not }
only last item appears selected...if can't done , have set selection underlying model how should go it???
also please note jlist has selection mode:
jlist.setselectionmode(listselectionmodel.multiple_interval_selection);
thanks in advance
although stanislasv answer valid, prefer avoid adding 1 selection interval another. instead, should prefer call jlist
associated listselectionmodel#setselectioninterval(int, int)
method :
jlist.getselectionmodel().setselectioninterval(0, 3)
if want list selection disjoint, you'll have write own listselectionmodel
.
Comments
Post a Comment