Tuesday, August 20, 2013

JTable.clearSelection() vs Jtable.getSelectionModel.clearSelection() - When to use what?

JTable.clearSelection() vs Jtable.getSelectionModel.clearSelection() -
When to use what?

I need to cancel all Selections within a JTable Model Object. Java
provides this function "clearSelection()" which does, what I need, as far
as I understand.
But I am confused why this function can be called on a JTable Object as
well as on a selection model for a jtable object
1) mytable.clearSelection();
2) mytable.getSelectionModel().clearSelection();
Both ways work, but I do not understand in what situation a
clearSelectuon() of a SelectionModel (like at 2) ) would make any sense.
As far as I understood SelectionModels, they are used to decide what kind
of selections a JTable allows. I use the SelectionModel to only allow a
Selection of exaclty one row
//allow only one row to be selected
mytable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Which way is to be prefered in what kind of situation? Is there a good
reason not to use way 1?
I would be glad if anyone has some beginnerfriendly explenation for that.
Thx in advance

No comments:

Post a Comment