1

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.

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);
Rohit Ghosh
  • 53
  • 11
  • try this solution in this [thread](http://stackoverflow.com/questions/3081713/how-to-set-the-textfield-is-not-visible-in-frame) – The Appsolit Dec 29 '16 at 10:14
  • @DataPro I can set visible and invisible . But will that show any values? Values showld be visble . Ex :- Like we see on right click-> properties-> file location. ? – Rohit Ghosh Dec 29 '16 at 10:28
  • 1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). .. – Andrew Thompson Dec 29 '16 at 12:54
  • .. 3) *".. the value should be visible in Eclipse"* What? The value should be invisible to the user but visible in your IDE? The text of the question suggests you want that the user type in one window, but the value be visible in another. Please [edit] the question and clarify what is actually required. – Andrew Thompson Dec 29 '16 at 12:54
  • @AndrewThompson Done Thank You – Rohit Ghosh Dec 30 '16 at 05:17
  • @DarkV1 read only value with no background borders etc . I already did it yesterday. – Rohit Ghosh Dec 30 '16 at 05:18
  • @RohitGhosh remember to accept an answer when you have what you were looking for. – AxelH Jan 31 '17 at 11:08

1 Answers1

2

if you want to make it read only than JLable is better option to do this work .

However if you want to use JTextfield than make text field as a private member and use a method to settext field hidden .

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(BorderFactory.createLineBorder(Color.white));

or

txt.setBorder(new LineBorder(Color.white,0));
Gaurav Varshney
  • 502
  • 5
  • 15