Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes why JButton and not others such as JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why JButton and not others such as JTable" Watch "why JButton and not others such as JTable" New topic

why JButton and not others such as JTable

budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
I have a question :
i was studying the mvc architecture of swings and saw that when it comes to JButton we never call the model to change the contents(such as actionCommand) instead we call the setActionCommand()
and in the source code i saw that it looks something like this :

now whenever we deal with Jslider or JTables then we always do changes in the model by calling the models and explicitly do changes in the model . We could have come up with similar code for sliders as well ? Why didn't we ?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19911

JSpinner has all the methods SpinnerModel has. JTable has all the methods TableModel has apart from addTableModelListener and removeTableModelListener.

You are right that JTable has no methods for adding rows. That's because the TableModel interface doesn't require implementing classes to support it; you could have an implementation with a fixed number of rows and columns. Changing the value of a cell is possible through the JTable though.

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: why JButton and not others such as JTable