Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使JTextField(eclipsewindowbuilder)为只读_Java_Eclipse_Swing_Windowbuilder - Fatal编程技术网

Java 如何使JTextField(eclipsewindowbuilder)为只读

Java 如何使JTextField(eclipsewindowbuilder)为只读,java,eclipse,swing,windowbuilder,Java,Eclipse,Swing,Windowbuilder,我想使我的JTextfield不可见且为只读,但该值必须显示在窗口框架中。我正在Eclipse中使用WindowBuilder JLabel lblLabel1 = new JLabel("Default DITA-OT File :"); lblLabel1.setBounds(10, 79, 123, 14); frmPdfPublisher.getContentPane().add(lblLabel1); JSeparator separator = new JSeparator();

我想使我的
JTextfield
不可见且为只读,但该值必须显示在窗口框架中。我正在Eclipse中使用WindowBuilder

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);

如果您想使它成为只读的,那么执行此操作的更好选择是
JLable

但是,如果您想使用
JTextfield
,请将文本字段设置为私有成员,并使用方法将文本字段设置为隐藏

class Example {

private JTextField tf;

public void hideTextField(){
    tf.setVisible(false);
} }
更改文本字段的颜色,使其与面板或框架的颜色相同

setBackground(Color.white);
并通过重写setboorder方法或将“null”传递给


在@DataPro中尝试此解决方案,我可以设置为可见和不可见。但这会显示出什么价值吗?价值观应该是可见的。例:-就像我们在右键单击->属性->文件位置上看到的一样?1) 为了更快地获得更好的帮助,请发布一个or。2) Java GUI必须在不同的操作系统、屏幕大小、屏幕分辨率等上工作,在不同的地区使用不同的PLAF。因此,它们不利于像素完美布局。而是使用布局管理器,或与…的布局填充和边框一起使用。。。。3) “。该值应该在Eclipse中可见”什么?该值应该对用户不可见,但在IDE中可见?问题的文本表明您希望用户在一个窗口中键入,但值在另一个窗口中可见。请回答问题并澄清实际需要的内容。@andrewhompson Done谢谢我可以这样做,但我想让我的值在其中可见,这是不可能的。此代码没有显示值可见。它也是不可见的。@RohitGhosh,更改文本字段的背景颜色,使其与面板或框架的颜色相同。只需删除边框。我对答案进行了更改,请检查。
setBorder(BorderFactory.createLineBorder(Color.white));

or

txt.setBorder(new LineBorder(Color.white,0));