what's the use of SelectionModels?

A

Abs

Hi!

I hope you can enlighten me but I don't see the use of
SelectionModels when JList, JTable, etc. have methods to work with
selections. Why do you use SelectionModels ?


Regards
 
C

Chris Smith

Abs said:
I hope you can enlighten me but I don't see the use of
SelectionModels when JList, JTable, etc. have methods to work with
selections. Why do you use SelectionModels ?

SelectionModel is quite useful when you want to change the basic way
that selection works for those components. For example, perhaps you
want a JTree component to only allow selection of leaf nodes; the
selection model can be used to accomplish this trivially.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
M

Michael Rauscher

Abs said:
Hi!

I hope you can enlighten me but I don't see the use of SelectionModels
when JList, JTable, etc. have methods to work with selections. Why do
you use SelectionModels ?

There are a couple of reasons for using a SelectionModel. A model
notifies it's listeners whenever it changes.

Imagine a file chooser. On the left side there's a tree containing
directories, on the right side there are the details of the current
selected directory (the selection).

What one expects in such situations is, that if he selects a directory
in the directory tree, the details are updated. To do this, you register
a TreeSelectionListener with the tree's TreeSelectionModel and from this
time on your listener is notified whenever the selection set changes.

Bye
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,688
Members
48,796
Latest member
Greg L.

Latest Threads

Top