wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Access TextField from another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Access TextField from another class" Watch "Access TextField from another class" New topic
Author

Access TextField from another class

Primoz Karnekaj
Greenhorn

Joined: Apr 19, 2009
Posts: 5
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
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Apr 19, 2009
Posts: 5
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

Joined: Oct 13, 2005
Posts: 38107
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Access TextField from another class
 
Similar Threads
JAVA GUI - Actions for Buttons/ActionListener/Event Handling
Does this piece of code hang for you all also ?
How do i get the value of a TextField component from another page?
answer to question no8 of sample questions is wrong
public vs. private modifier