JTextField is "empty" even if the user puts text into it
Why is my JTextField
"empty" even if I put text into it?
I am making a Java Program which creates a PDF File. I retrieve a text field input from field3.getText();
but it is always null
, even if it’s not empty. Thus the text I want to be on the PDF is not showing.
contentStream.beginText(); contentStream.setFont(font2, fontSize3); contentStream.newLineAtOffset(50, 690); String name7; try { name7 = GUI.field3.getText(); contentStream.showText(name7); } catch (Exception e) { System.out.println("Error"); } contentStream.endText(); //field3 piece of code in another class: public class GUI { static String adress; static String name; static String country; static String postal; static String companyname; static String tel; static JTextField field2; static JTextField field3; static JTextField field_4; static JTextField field4; JTextField field5; public static void main(String[] args) { } public GUI() { field3 = new JTextField(""); } }
I would suggest removing the ‘static’ keyword from the variables initialized to make them instance variables.