Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Disable Multiselect of Listbox (Jlist) in Java

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);
like image 737
Raj Avatar asked May 09 '14 05:05

Raj


People also ask

How to use standard listboxes in a Java Swing application?

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.

What is jlist object in Java?

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.

What is the use of setselectionmode () in jlist?

JList − To create a standard list. JList.setSelectedIndex (index); − To select an item. JList.setSelectionMode (); − To set the selection mode.

What is the difference between LISTDATA and listmodel in jlist?

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.


1 Answers

Use :

JList list = new JList(); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

More informations on docs.oracle.com : jList : setSelectionMode

like image 122
Psyker Avatar answered Sep 28 '22 03:09

Psyker