| Author |
what am i doing wrong
|
john mattucci
Ranch Hand
Joined: Nov 03, 2000
Posts: 331
|
|
IM TRYING TO ADD A ROW TO A JTABLE, AND FOR SOME REASON ITS NOT WORKING, WHAT AM I DOING WRONG I HAVE LOOKED THROUGH 100+ PAGES AND I HAVE FOUND NOTHING private JTable getScrollPaneTable() { if (ivjScrollPaneTable == null) { try { dm = new DefaultTableModel(o,1); ivjScrollPaneTable = new JTable(dm) { public void tableChanged(TableModelEvent e) { super.tableChanged(e); int row = e.getFirstRow(); int column = e.getColumn(); if(column == 1 && isWord((String)getValueAt(row, column))) { Object o[] = null; dm.setNumRows(2); dm.addRow(o); } repaint(); } private boolean isWord(String param) { char c [] = param.toCharArray(); int size = c.length; Character test = new Character(c[0]); for(int i = 0; i < size; i++) { if(test.isLetter(c[i])) return true; } return false; } }; getJScrollPane1().setColumnHeaderView(ivjScrollPaneTable.getTableHeader()); getJScrollPane1().getViewport().setBackingStoreEnabled(true); ivjScrollPaneTable.setModel(dm); initColumnSizes(ivjScrollPaneTable, dm); //ivjScrollPaneTable.sizeColumnsToFit(3); ivjScrollPaneTable.setCellSelectionEnabled(true); ivjScrollPaneTable.setColumnSelectionAllowed(true); ivjScrollPaneTable.setBounds(0, 0, 200, 200); ivjScrollPaneTable.setRowHeight(22); return ivjScrollPaneTable; }
|
 |
Chantal Ackermann
Ranch Hand
Joined: Sep 28, 2000
Posts: 508
|
|
hi, I'm not sure for what's that if-clause. anyway, you're adding the row inside this if-clause. more exactly you're adding: Object[] o = null; dm.addRow(o); thus you're adding the value null. setting the rows is not necessary, i never did that. I extend the DefaultTableModel. the data should be put in a Hashtable where the key indicates the cell (Point(col, row)). adding a row means than, to add the cell values of a row. the table will be updated by the model automatically. (ok, maybe you'll have to fire an event inside of the addRow method of your TableModel. see the swing tutorial.) chantal
|
 |
 |
|
|
subject: what am i doing wrong
|
|
|