15,000 Jobs Available in:
Java, ASP, C#, PHP, SQL, SAP, MySQL and many more.
- Class Quick -
The moose likes Swing / AWT / SWT / JFace and the fly likes A newbie got stuck ! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "A newbie got stuck !" Watch "A newbie got stuck !" New topic
Author

A newbie got stuck !

Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Posts: 51

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
Posts: 15021



Panel 1 needs a reference to panel 2 and panel 2 needs a getter for your text area for this to work.


My Blog | DZone Articles
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Posts: 51
Thank you ... it really helped me ...
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Posts: 51
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 Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

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
Posts: 51


Panel2 is an instance variable, instantiated at the Constructor of Panel1



this is in my pannel2

Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

And Panel2 is the exact same instance you added to your GUI? You haven't created another, invisible panel?
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Posts: 51
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
Posts: 51


This is my NetBeans Project file

My NetBeans Project
Michael Dunn
Rancher

Joined: Jun 09, 2003
Posts: 3619
creating a new MyNewPanel() is not passing a reference of the one on the screen.

some changes



and


Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

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 by Rob Prime

Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Posts: 51
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.
 
 
subject: A newbie got stuck !
 
developer file tools