Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Copying a value from 1 JPanel to another

 
Steve Gebert
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Scott Delap
author
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic