菜鸟小问题:大哥们快来哦!!!!
一个文本框
JTextField t;
我想用它只用来显示数据 用户不能在文本框里输入数据 这个用什么方法?好像有个方法可以把它设成不可修改的 但是具体怎么写不知道 大哥们快来啊!!!
------解决方案--------------------t.setEditable(false);
------解决方案--------------------/**
* Sets the specified boolean to indicate whether or not this
* <code> TextComponent </code> should be editable.
* A PropertyChange event ( "editable ") is fired when the
* state is changed.
*
* @param b the boolean to be set
* @see #isEditable
* @beaninfo
* description: specifies if the text can be edited
* bound: true
*/
public void setEditable(boolean b) {
if (b != editable) {
boolean oldVal = editable;
editable = b;
if (editable) {
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
} else {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
enableInputMethods(editable);
firePropertyChange( "editable ", Boolean.valueOf(oldVal), Boolean.valueOf(editable));
repaint();
}
}