ListSelectionModel and ListModel

Hi,

I am creating my own custom ListModel by extending the AbstractListModel. I want to set the set the selection mode to SINGLE selection. Anything that makes use of the custom ListModel should by default only be able to select one row at a time, unless they override a method to set the selection to something else. I'm guessing I need to make use of ListSelectionModel.

I have an interface which will be implemented by AbstractListModel, and the AbstractTableModel too. The selection needs to be set to SINGLE selection for both.

Can anyone give some ideas - I can't find any examples on ListSelectionModel.

Thanks.

[651 byte] By [sand_samuraia] at [2007-11-27 10:49:39]
# 1

> I have an interface which will be implemented by AbstractListModel, and the AbstractTableModel too.

As far as I have understood you're trying to write a ListModel (by subclassing ListModel) and you want to have AbstractListModel and AbstractTableModel implement that. This is not possible as AbstractListModel and AbstractTableModel are API classes. Or perhaps I misunderstood you.

java_knighta at 2007-7-29 11:20:35 > top of Java-index,Java Essentials,New To Java...
# 2

You can set the selection mode by calling setSelectionMode(...) on your JList.

Concerning JComboBoxes, you always can select only one item at a time.

java_knighta at 2007-7-29 11:20:35 > top of Java-index,Java Essentials,New To Java...
# 3

I have an interface which has certain methods to be implemented by a TableModel and a ListModel. Both models also needs to be able to restrict the selections to single selection.

so the JTable that makes use of the TableModel by default would only be single selection unless explicitly changed via the setSelectionMode method.

likewise for the JList that makes use of the ListModel

class structure is as follows:

class MyTableModel extends AbstractTableModel implements MyInterface{

...

}

class MyListModel extends AbstractListModel implements MyInterface{

...

}

Message was edited by:

sand_samurai

sand_samuraia at 2007-7-29 11:20:35 > top of Java-index,Java Essentials,New To Java...
# 4

I'm not sure about that, but I think that the selection type (single element, single interval, or multiple intervals) can only be set in the JTable or JList, not in their models.

java_knighta at 2007-7-29 11:20:35 > top of Java-index,Java Essentials,New To Java...