开发者

Override list selection in Swing

I want to make list selection such that when I first select an item it get selected after that when I select second item then both should get selected that is first selection should remain as it is. I have set list selection mode to multiple selection. But still has to press ctrl key to do the thing. I want to do it without pressing ctrl key.

How to remain list item selected?

Here is the line where I set the selection mode:

list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELEC开发者_如何学GoTION);

Edit: AS suggested by StanislavL I tried following but it did not worked for me.

            DefaultListSelectionModel model = new DefaultListSelectionModel();
            model.removeSelectionInterval(0, 2);
            user_list.setSelectionModel(model);


It is a real well known convention that multi select requires pressing the Ctrl key. Same with using the Shift key to select a range of values.

Personally I would never spend effort on changing this behaviour, because it would confuse users that are already familiar with other applications.


Try to replace ListSelectionModel in the list. Use

public void setSelectionModel(ListSelectionModel selectionModel)

You can use the DefaultListSelectionModel and override

public void removeSelectionInterval(int index0, int index1)

call super.remove() if the items are already selected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜