I want to make my JTextfield
invisible and read only but the value must be shown in a window frame. I am using window builder in Eclipse.
我想让我的JTextfield不可见且只读,但值必须显示在窗口框架中。我在Eclipse中使用窗口构建器。
JLabel lblLabel1 = new JLabel("Default DITA-OT File :");
lblLabel1.setBounds(10, 79, 123, 14);
frmPdfPublisher.getContentPane().add(lblLabel1);
JSeparator separator = new JSeparator();
separator.setBounds(10, 140, 414, 2);
frmPdfPublisher.getContentPane().add(separator);
JSeparator separator_1 = new JSeparator();
separator_1.setBounds(10, 257, 414, 2);
frmPdfPublisher.getContentPane().add(separator_1);
textField_1 = new JTextField();
textField_1.setBounds(138, 76, 286, 20);
frmPdfPublisher.getContentPane().add(textField_1);
textField_1.setColumns(10);
textField_1.setVisible(false);
1 个解决方案
#1
2
if you want to make it read only than JLable
is better option to do this work .
如果你想让它只读,那么JLable是做这项工作的更好选择。
However if you want to use JTextfield
than make text field as a private member and use a method to settext field hidden .
但是,如果要使用JTextfield而不是将文本字段作为私有成员,并使用隐藏的settext字段的方法。
class Example {
private JTextField tf;
public void hideTextField(){
tf.setVisible(false);
} }
Change the color of Textfield and make it same As color of Panel or frame .
更改文本字段的颜色并使其相同作为面板或框架的颜色。
setBackground(Color.white);
And Remove Border Either by overriding setBorder method or by Passing "null" to
并通过重写setBorder方法或通过传递“null”来删除边框
setBorder(BorderFactory.createLineBorder(Color.white));
or
txt.setBorder(new LineBorder(Color.white,0));
#1
2
if you want to make it read only than JLable
is better option to do this work .
如果你想让它只读,那么JLable是做这项工作的更好选择。
However if you want to use JTextfield
than make text field as a private member and use a method to settext field hidden .
但是,如果要使用JTextfield而不是将文本字段作为私有成员,并使用隐藏的settext字段的方法。
class Example {
private JTextField tf;
public void hideTextField(){
tf.setVisible(false);
} }
Change the color of Textfield and make it same As color of Panel or frame .
更改文本字段的颜色并使其相同作为面板或框架的颜色。
setBackground(Color.white);
And Remove Border Either by overriding setBorder method or by Passing "null" to
并通过重写setBorder方法或通过传递“null”来删除边框
setBorder(BorderFactory.createLineBorder(Color.white));
or
txt.setBorder(new LineBorder(Color.white,0));