Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

editing text in JTable

Status
Not open for further replies.

msloan

Programmer
May 30, 2001
39
US
Hi,

I have created a table, and have applied both a cell renderer and cell editor to the same column. I also have overridden the 'isCellEditable()' so that my column is editable. The editor will only allow whole numbers to be entered. So far this is working fine, but when I edit the cell and then move to the next row, the data I entered in the first cell is lost. I have attached some of the code...

What is it that I am missing?

Thanks

Matt
Code:
//create a template for number fields (align right)
DefaultTableCellRenderer rndNumber = new DefaultTableCellRenderer();
rndNumber.setHorizontalAlignment(JLabel.RIGHT);

tblItems.getColumnModel().getColumn(4).setCellRenderer(rndNumber);

JTextField txtEditor = new JTextField();
      txtEditor.setDocument(new GenevaCommon.WholeNumberDocument(6));
      TableCellEditor tblEditor = new DefaultCellEditor(txtEditor);

      tblItems.getColumnModel().getColumn(4).setCellEditor(tblEditor);
 
Did you overwrite your setValueAt() method?
You can take a look at the JTable example in c:\jdk1.3\demo\jfc\TableExample\src

That should help you out.

Leon
 
That's exactly what I was missing!

Thanks for the help!!!

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top