• Post Reply Bookmark Topic Watch Topic
  • New Topic

A newbie got stuck !

 
Tirthankar Mukherjee
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Panel 1 needs a reference to panel 2 and panel 2 needs a getter for your text area for this to work.
 
Tirthankar Mukherjee
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ... it really helped me ...
 
Tirthankar Mukherjee
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the exact code you are using to update it?
 
Tirthankar Mukherjee
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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



this is in my pannel2

 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Panel2 is the exact same instance you added to your GUI? You haven't created another, invisible panel?
 
Tirthankar Mukherjee
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is my NetBeans Project file

My NetBeans Project
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
creating a new MyNewPanel() is not passing a reference of the one on the screen.

some changes



and


 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tirthankar Mukherjee
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!