Author
A newbie got stuck !
Tirthankar Mukherjee
Ranch Hand
Joined: Apr 08, 2006
Messages: 44
posted Jul 09, 2009 10:19:11
I am trying to write a small java applications. I created my 1st JPanel , and added a JTextBox and a button to it, in a 2nd JPanel I added a JTextBox only, now I added this 2 JPanel to a JFrame , I want to want to put up the text in JtextBox of Panel1 to JtextBox of Panel2 on hitting the button of JPanel1. I am adding an image for clarification , this small piece of code is done except the event-handling (the most important part).
If someone clears my doubts, and provides some code/link how to write codes for this kind of event handling, then it would be very helpful.
Please help, thanks in Advance.
Gregg Bolinger
Sheriff
Joined: Jul 11, 2001
Messages: 13666
posted Jul 09, 2009 10:49:43
Panel 1 needs a reference to panel 2 and panel 2 needs a getter for your text area for this to work.
"Fookin Prawns"
Tirthankar Mukherjee
Ranch Hand
Joined: Apr 08, 2006
Messages: 44
posted Jul 09, 2009 11:06:15
Thank you ... it really helped me ...
Tirthankar Mukherjee
Ranch Hand
Joined: Apr 08, 2006
Messages: 44
posted Jul 09, 2009 11:59:16
ok , I did exactly the same, it works but there is a problem. When I try to get my Text (with SOP statements), of JtextArea2, I get what is expected, but in the UI it remains the same doesnot update.
Rob Prime
Bartender
Joined: Oct 27, 2005
Messages: 8776
posted Jul 09, 2009 12:49:11
Can you show us the exact code you are using to update it?
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Tirthankar Mukherjee
Ranch Hand
Joined: Apr 08, 2006
Messages: 44
posted Jul 09, 2009 12:56:39
Panel2 is an instance variable, instantiated at the Constructor of Panel1
this is in my pannel2
Rob Prime
Bartender
Joined: Oct 27, 2005
Messages: 8776
posted Jul 09, 2009 13:00:43
And Panel2 is the exact same instance you added to your GUI? You haven't created another, invisible panel?
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Tirthankar Mukherjee
Ranch Hand
Joined: Apr 08, 2006
Messages: 44
posted Jul 09, 2009 13:02:30
MynewPannel.java
I know the full code with "system genereted one" .. its pretty bad ... even I dislike it ... but please help
Tirthankar Mukherjee
Ranch Hand
Joined: Apr 08, 2006
Messages: 44
posted Jul 09, 2009 13:29:19
This is my NetBeans Project file
My NetBeans Project
Michael Dunn
Rancher
Joined: Jun 09, 2003
Messages: 3090
posted Jul 09, 2009 13:36:59
creating a new MyNewPanel() is not passing a reference of the one on the screen.
some changes
and
Rob Prime
Bartender
Joined: Oct 27, 2005
Messages: 8776
posted Jul 09, 2009 13:37:44
Just what I though. Your MyPanel instance has its own copy of MyNewPanel that is not added to the GUI.
You should give it a reference to the actual panel:
Heh, Michael beat me to it
This message was edited 1 time. Last update was at Jul 09, 2009 13:38:35 by Rob Prime
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Tirthankar Mukherjee
Ranch Hand
Joined: Apr 08, 2006
Messages: 44
posted Jul 09, 2009 13:48:58
Oh my GOD !!! Swing is swing pretty fast but I will hang on ... JavaRanch rocks !!
Most importantly many many thanks Rob and all of the above contributors.