Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access TextField from another class

 
Primoz Karnekaj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have two classes - main and GUI.
In main i start the GUI window like this:


On this window I have a textField which I want to update from my main class. However, I don't know how to access it. I tried

but it doesn't exist. Please help me, I got rusty in Java!
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post some code. Is JTextField the variable name of the textbox? Is it declared as an instance variable of the GUI class? Please refrain from using the class name as the variable name...
 
Primoz Karnekaj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey John,
I managed to solve this problem. I had to set the modifier property of JTextField (yes, a textfield) to public and remove the tick from "Use local variable" - Both under Code tabs in Netbeans.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Primoz Karnekaj wrote:. . . I had to set the modifier property of JTextField (yes, a textfield) to public and remove the tick from "Use local variable" . . .
Both of which look like mistakes to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic