I have a JTable that I want to use to display some data (a String and a Boolean in each row). The data is maintained by my own class. Is there some way to bind the data model to the JTable, so that when I add to the model, the JTable is dynamically updated and when I remove something from the model, the row is removed from the JTable?
I have previously worked with Flex and Actionscript, and this is very easy to do there with data binding, so I’m just wondering how it’s done in Java.
Thanks.
You will need to have your dataset implement the
TableModelinterface. if you do that then you can apply it to the JTable. If you extendAbstractTableModelyou will inherit some event firing methods that your table will handle and will update the view. see this tutorial. Note that the default implementation ofJTablewill renderer your data for you, and if a Boolean is found, it will show up as a check box.