Question

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);
Était-ce utile?

La solution

Use :

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

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

Autres conseils

Use setEnabled(boolean enabled) inherited by JLIst from JComponent to enable / disable it like this:

yourJlistObject.setEnabled(false);

From JComponent JavaDocs:

public void setEnabled(boolean enabled) Sets whether or not this component is enabled. A component that is enabled may respond to user input, while a component that is not enabled cannot respond to user input. Some components may alter their visual representation when they are disabled in order to provide feedback to the user that they cannot take input. Note: Disabling a component does not disable its children. Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top