问题
I am creating a small system using swing via netbeans(I must say i am new to swing). look at the below image .

in this the id = "ST100" i need to add it to a jTextfield automatically in the below interface when i open it

so i coded it in the first interface source code as seen below after making the arrowed textfield's access modifier "public" which is in the second interface.

but the wanted text is not auto filling why is it?
the relevent code in the first interface
addSubjects add = new addSubjects();
add.stid1.setText(stdid);
"stdid" is the String input of the 1st interface text field. "addSubjects" is the frame name of the 2nd interface. "stid1" is the variable name of the arrowed text field in the 2nd interface.
there are no codes in the second interface. what i want is to after clicking the submit button in the first interface the arrowed text field in the 2nd interface must autofill the same String which i give to the first interaface arrowed textfield.
回答1:
So, you want to pass the String value from one class to another.
Well, the easiest and (best) way to achieve this is by creating the 2nd class as an inner class of the first class.
All you have to do is to Paste your 2nd class code inside your 1st class code (Don't paste it inside the main method)
Remove the
static
word from your 2nd class's main methodDeclare a String in your 1st class as follows,
String StudentId;
After you collect the Id from the user, intialize the above mentioned String as,
String StudentId = "student_id_to_show";
Now,in your 2nd class code(which is inner class of the 1st class), set the text of the jTextField as,
jTextField.setText(StudentId);
All done,Cheers!!!
来源:https://stackoverflow.com/questions/50890382/auto-filling-a-jtextfield-in-java-swing