• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Editing a cell in JTable - urgent

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic