aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Copying a value from 1 JPanel to another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Copying a value from 1 JPanel to another" Watch "Copying a value from 1 JPanel to another" New topic
Author

Copying a value from 1 JPanel to another

Steve Gebert
Greenhorn

Joined: May 07, 2004
Posts: 17
Hi - I am having a heck of a time with what I am sure is a simple issue. I have a frame with a tabbed pane. In this pane I have placed two JPanels that are separate classes. I am trying to copy the value of a text field from one panel to the other based on the button press action on the second. I seem to have missed the concept of visibility here. What I am trying to do is pretty simple in VB etc but for the life of me I can't seem to get it here. I need this so that I can do updates on records in a database and promulgate the record id's. Any help woudl be greatly appreciated. Thanks in advance.


Here is the code for the frame that holds the tabbed panel etc;


Here is the code for the 1st panel


And here is the code for the second and problematic panel;


And finally here is the code for the bootstrap program that contains my Main;

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632

Scott Delap
author
Ranch Hand

Joined: Apr 05, 2005
Posts: 73
Sounds like you need some sort of shared "controller" or data model behind the panels. You would share this class and then have the panel set a value on it. It would then update any listeners (one which could be your other panel).

Scott Delap
ClientJava.com
Desktop Java Live
Steve Gebert
Greenhorn

Joined: May 07, 2004
Posts: 17
Thanks guys - I am on the track of it now. One each of the panels I wrote the following;

public void setParent(MainFrame myMainFrame)
{
this.myMainFrame = myMainFrame;
}

and on the frame I added;
myPanelA.setParent(this);
myPanelB.setParent(this);

and on PanelB I added this line;
secondTest_txt.setText(myMainFrame.myPanelA.test_txt.getText());

This gives me a reference to each panel. Works great. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Copying a value from 1 JPanel to another