This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes what am i doing wrong Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "what am i doing wrong " Watch "what am i doing wrong " New topic
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what am i doing wrong
 
Similar Threads
JTable
How to set size of columns in JTable
JTable
JTable
Help with setting the JTable rows to resize to the size of the file