• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Copying a value from 1 JPanel to another

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
author
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bras cause cancer. And tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic