Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to add a jpassword field in a JTable  RSS feed

 
kavitha pp
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to add a Jpassword field in a JTable

My application requires the need for the creation of a new user.
So the new user window appears in a jtable ,having the columns as user name and password.so my doubt is how to add Jpassword field to the JTable.
 
Karthikeyan Chandrasekaran
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a custom cell editor and use JPasswordField as editing component
[ January 04, 2007: Message edited by: Karthikeyan Chandrasekaran ]
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically, you can't add a JPasswordField (or any other component) to a JTable. What you can do is set a cell renderer and a cell editor that give the effect of a JPasswordField. The editor part is pretty simple to do. Presuming the passwords are in column #1:

JPasswordField pwf = new JPasswordField();
DefaultCellEditor editor = new DefaultCellEditor(pwf);
yourTable.getColumnModel().getColumn(1).setCellEditor(editor);

But you need to set a renderer too or else all the passwords (except for the one being edited) will be visible.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!