How do I disable multiselect in listbox (Jlist) of java?
Code:
configId.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
defaultModel = new FTCSDefaultListModel();
defaultModel.addElement(cecfgVo.getConfigIdList());
configId = new FTCSList(defaultModel);
configId.setVisibleRowCount(10);
JScrollPane pane = new JScrollPane(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
pane.setPreferredSize(new Dimension(100,100));
pane.setViewportView(configId);
Following example showcase how to use standard listboxes in a Java Swing application. We are using the following APIs. JList − To create a standard list. JList.setSelectedIndex (index); − To select an item. JList.setSelectionMode (); − To set the selection mode.
Java JList. The object of JList class represents a list of text items. The list of text items can be set up so that the user can choose either one item or multiple items.
JList − To create a standard list. JList.setSelectedIndex (index); − To select an item. JList.setSelectionMode (); − To set the selection mode.
JList(ary[] listData) Creates a JList that displays the elements in the specified array. JList(ListModel<ary> dataModel) Creates a JList that displays elements from the specified, non-null, model.
Use :
JList list = new JList();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
More informations on docs.oracle.com : jList : setSelectionMode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With