Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help me in getting the value of a cell after editing in Jtable

798700Oct 13 2010 — edited Oct 13 2010
Hi All,

Can any one help me in getting the value of a cell after editing it

and no idea of how to add focus to the cell ,

I am using a piece of code as follows
 for (int col = 0; col < this.getTable().getColumnCount(); col++) {
				
		     String columnName = this.getTable().getColumnName(col);
			TableColumn column = tableColumnModel.getColumn(col);
			
			if (columnName.equals("Application")) {
				column.setPreferredWidth(150);
			} else if (columnName.equals("Warning"))
              {
				column.setPreferredWidth(60);
						   
			 }else if (columnName.equals("Critical"))  
			{
				column.setPreferredWidth(60);
				for(int row = 0; row < this.getTable().getRowCount(); row++){
					column.setCellEditor(new MyTableCellEditor());	
				  }




@SuppressWarnings("serial")
public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor {
	JPanel jpanel = new JPanel(new BorderLayout(5,5));
  
	JTextField tfield = new JTextField();
	
	
	public MyTableCellEditor()
	{
		jpanel.add(tfield);
	}
	
	
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
	{
		tfield.setText(String.valueOf(value));
		return jpanel;
	}
	
	public Object getCellEditorValue()
	{
		
		//String  nucritical = tfield.getText();
		//tfield.getText(Integer.parseInt(nucritical));
		 // int i = Integer.parseInt(nucritical);
		
		//System.out.println(i);
		 return tfield.getText();
	   
	}
}
Please help me in this

Thank you very much
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2010
Added on Oct 13 2010
4 comments
54 views