[英]JTable cloumn doesn't get focused anymore
Recently I have a small problem with one column in a JTable: since I edited it's DefaultTableCellRenderer the password column doesn't get focused, when I focus a row in the table. 最近,我在JTable中的一个列上遇到了一个小问题:由于我编辑了它的DefaultTableCellRenderer,因此当我在表中聚焦一行时,密码列没有被聚焦。 Here's a screenshot an my code:
这是我的代码的屏幕截图 :
inputsTable.getColumn("Passwort").setCellRenderer(new DefaultTableCellRenderer(){
private final String ASTERISKS = "*";
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
int length =0;
if (value instanceof String) {
length = ((String) value).length();
} else if (value instanceof char[]) {
length = ((char[])value).length;
}
setText(asterisks(length));
return this;
}
private String asterisks(int length) {
if (length > ASTERISKS.length()) {
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
sb.append('*');
}
return sb.toString();
} else {
return ASTERISKS.substring(0, length);
}
}
});
I have already tried some different options, but they didn't help me, unfortunately. 我已经尝试了一些不同的选择,但是不幸的是,它们并没有帮助我。 Does anyone of you have eventually a clue, is there maybe some better implementation of a password column in a JTable without this problem?
你们最终有什么头绪吗,也许在JTable中可以更好地实现密码列,而不会出现此问题? Thanks in advance!
提前致谢!
The DefaultTableCellRenderer
implementation posted sets no formatting based upon the current state (in particular the isSelected
parameter). 发布的
DefaultTableCellRenderer
实现不基于当前状态(尤其是isSelected
参数)设置任何格式。 To keep default formatting, consider calling the parent method prior to your customization. 要保留默认格式,请考虑在自定义之前调用父方法。
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
//do your customization here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.