aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Editing a cell in JTable - urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Editing a cell in JTable - urgent" Watch "Editing a cell in JTable - urgent" New topic
Author

Editing a cell in JTable - urgent

Arun Kumarr Jeyaseelan
Greenhorn

Joined: Nov 25, 2004
Posts: 2
Hi,
I am editing my Custom Table cell.while I am editing the cell the value is shown, but once I come out of the cell it is vanishing.
Even thou' if I render the cell as a Textfield it is not solved.
If anybody can help me,please.
Thanks.
sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
Hi Arun Kumar,

What about your previous problem (About Password Field)?.


I am sending more code, use this in your program

1) add this to the main class
table.getColumnModel().getColumn(0).setCellRenderer(new PasswordRenderer());

table.getColumnModel().getColumn(0).setCellEditor(new PasswordEditor(new JCheckBox()));


2) The PasswordRenderer class.,

class PasswordRenderer extends JPasswordField implements TableCellRenderer
{

public PasswordRenderer() {
setOpaque(true);
}

public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table,
Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
setText( (value ==null) ? "" : value.toString() );
return this;
}
}

3) The PasswordEditor class.,

class PasswordEditor extends javax.swing.DefaultCellEditor {
protected JPasswordField password;

public PasswordEditor(JCheckBox checkBox) {
super(checkBox);

password = new JPasswordField();
password.setOpaque(true);
}

public java.awt.Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column)
{
String label = (value ==null) ? "" : value.toString();
password.setText( label );
return password;
}

public Object getCellEditorValue()
{
String label = new String(password.getPassword());
System.out.println("Password is: "+label);
return label;
}
}

All The Best.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Editing a cell in JTable - urgent
 
Similar Threads
Making a cell in JTable in Editing Mode by default
about cell editing in JTable
how to prevent cell editing of a partyicular cell in a jtable
cell editing in JTable
Problem with cell Editing of three columns