The key to java object-oriented programming is the fucking cast. Remember that. When you write your own table model for JTable, MyTableModel, and you have created your table as
JTable table = new JTable(new MyTableModel());and you want to use a particular method, say addRow(), you can bang your head up against the wall for hours, as I did, trying to:
(table.getModel()).addRow();getModel() always returns an instance of javax.swing.table.TableModel. That base class doesn't have shit. You need to cast it instead:
((MyTableModel)table.getModel()).addRow();Now you're in business. And so am I, for now. Till I forget again.
That's the problem in using so many different languages. You forget all the nuances of one while you're learning another. Then you go back to the former one and repeat all your previous mistakes ad nauseam.
Back to blog or home page
last updated 2013-01-10 20:15:20. served from tektonic