Вопрос

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);
Это было полезно?

Решение

Use :

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

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

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top