Accessing controls in JFrame from parent.

Posted 15 April 2012 - 09:35 AM

Hi. I have a program with various JFrames controlled by a TabbedPane. I need to be able to access the controls on the JFrames, but I'm not sure how. I bet there's something about this on there internet somewhere, but I don't know how to word the question.

Replies To: Accessing controls in JFrame from parent.

Re: Accessing controls in JFrame from parent.

for one, there is no textPane in your Info class. There is a textField in your Info class though. You need to use the right terms if you expect to reach it.

You have declared your Info() class to be public.
But you haven't declared TextField as public. I'm sure its the same in Java as my native C# that you have to specify every object as public if you want to see it from outside of the class it was made in. If you don't specify public, it is therefore private.

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 09:52 AM

First I guess you talk about JTabbedPane when you write about TabbedPane
Second Initialize() has to be declared void and is not called by Main constructor
Third you can't put a JFrame into another JFrame so you can put a JFrame in a JTabbedPane
Fourth no reason for your JTextField to be static it is a bad design

Re: Accessing controls in JFrame from parent.

for one, there is no textPane in your Info class. There is a textField in your Info class though. You need to use the right terms if you expect to reach it.

You have declared your Info() class to be public.
But you haven't declared TextField as public. I'm sure its the same in Java as my native C# that you have to specify every object as public if you want to see it from outside of the class it was made in. If you don't specify public, it is therefore private.

Like I said, this is a mockup code example. It's not my actual program. I'll look at it again, I guess.

pbl, on 15 April 2012 - 09:52 AM, said:

First I guess you talk about JTabbedPane when you write about TabbedPane
Second Initialize() has to be declared void and is not called by Main constructor
Third you can't put a JFrame into another JFrame so you can put a JFrame in a JTabbedPane
Fourth no reason for your JTextField to be static it is a bad design

Happy coding

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! .

Re: Accessing controls in JFrame from parent.

Posted 15 April 2012 - 10:00 AM

If the only reason of the existence of the Info class is to hold a JTextField and you want to access this JTextField from the Main class simply make it an inner class and declare the JTextField in the Main class

Re: Accessing controls in JFrame from parent.

for one, there is no textPane in your Info class. There is a textField in your Info class though. You need to use the right terms if you expect to reach it.

You have declared your Info() class to be public.
But you haven't declared TextField as public. I'm sure its the same in Java as my native C# that you have to specify every object as public if you want to see it from outside of the class it was made in. If you don't specify public, it is therefore private.

Like I said, this is a mockup code example. It's not my actual program. I'll look at it again, I guess.

pbl, on 15 April 2012 - 09:52 AM, said:

First I guess you talk about JTabbedPane when you write about TabbedPane
Second Initialize() has to be declared void and is not called by Main constructor
Third you can't put a JFrame into another JFrame so you can put a JFrame in a JTabbedPane
Fourth no reason for your JTextField to be static it is a bad design

Happy coding

I'm assuming that you meant you can't put a JFrame into a TabbedPane. I assure you, you can. I have it right here on my screen! .

Also, I know that Initialize has to be void and called by Main and all that, this is just a quick example .

P.S. I think we're all getting a bit confused. This is my code that puts a JPanel inside a TabbedPane, not a JFrame. In Main.java, I need to access the textField variable, but I can't do that when the variable is initialized.