Adding same object(jtextfield) to different cards in card layout

Have a combo box with 3 items which changes cards in a cardLayout.
Have 3 panels as card in a cardLayout.
Want to reuse the field txtName, lblName in pnlName and reuse txtAge, lblAge in pnlAge in all the cards.
It only appears in the last card3 panel(i.e the last panel referenced)
Is there a way I can show the same object(pnlName, pnlAge) in all the cards,
Below is the code, any solution is welcome.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CardLayoutTest implements ItemListener {
JPanel cards; //a panel that uses CardLayout
public void addComponentToPane(Container pane) {
//Put the JComboBox in a JPanel to get a nicer look.
JPanel comboBoxPane = new JPanel(); //use FlowLayout
String comboBoxItems[] = { "Name", "ShortDetail","FullDetail"};
JComboBox cb = new JComboBox(comboBoxItems);
cb.setEditable(false);
cb.addItemListener(this);
comboBoxPane.add(cb);
          JLabel lblName, lblAddress, lblAge;
          JCheckBox chkMarried;
          JRadioButton rdbMale, rdbFemale;
          JTextField txtName, txtAddress, txtAge, txtSex;
          JPanel pnlName = new JPanel(new FlowLayout(FlowLayout.LEFT));
          pnlName.add(lblName = new JLabel("Name"));
          pnlName.add(txtName = new JTextField(10));
          JPanel pnlAddress = new JPanel(new FlowLayout(FlowLayout.LEFT));
          pnlAddress.add(lblAddress = new JLabel("Address"));
          pnlAddress.add(txtAddress = new JTextField(10));
          JPanel pnlAge = new JPanel(new FlowLayout(FlowLayout.LEFT));
          pnlAge.add(lblAge = new JLabel("Age"));
          pnlAge.add(txtAge = new JTextField(3));
          JPanel pnlSex = new JPanel(new FlowLayout(FlowLayout.LEFT));
          pnlSex.add(rdbMale = new JRadioButton("Male"));
          pnlSex.add(rdbFemale = new JRadioButton("Female"));
          JPanel pnlMarried = new JPanel(new FlowLayout(FlowLayout.LEFT));
          pnlMarried.add(chkMarried = new JCheckBox("Married"));
          //pnl3.add(lblName = new JTextField(10));
          JPanel card1 = new JPanel(new GridLayout(0,1));
          card1.add(new JLabel("Card1"));
          card1.add(pnlName);
          card1.add(pnlAge);
          JPanel card2 = new JPanel(new GridLayout(0,1));
          card2.add(new JLabel("Card2"));
          card2.add(pnlName);
          card2.add(pnlAge);
          card2.add(pnlAddress);
          JPanel card3 = new JPanel(new GridLayout(0,1));
          card3.add(new JLabel("Card3"));
          card3.add(pnlName);
          card3.add(pnlAge);
          card3.add(pnlSex);
          card3.add(pnlMarried);
//Create the "cards".
JPanel card1 = new JPanel();
card1.add(new JButton("Button 1"));
card1.add(new JButton("Button 2"));
card1.add(new JButton("Button 3"));
JPanel card2 = new JPanel();
card2.add(new JTextField("TextField", 20));
     JPanel card3 = new JPanel();
card3.add(new JLabel("Label"));
     JPanel card4 = new JPanel();
card4.add(new JCheckBox("Hello Holla"));
JPanel card5 = new JPanel();
          cards.add();
//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(card1, "Name");
cards.add(card2, "ShortDetail");
cards.add(card3, "FullDetail");
pane.add(comboBoxPane, BorderLayout.PAGE_START);
pane.add(cards, BorderLayout.CENTER);
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout)(cards.getLayout());
cl.show(cards, (String)evt.getItem());
private static void createAndShowGUI() {
JFrame frame = new JFrame("CardLayoutTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CardLayoutTest demo = new CardLayoutTest();
demo.addComponentToPane(frame.getContentPane());
     frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}

I'm 99% sure that you cannot have the same txtfields/combos in different JPanels at the same time, which explains why they only appear in the last panel they are added to... but I guess you already knew that.
You could add these components to the panel you wish to show each time you change panels.
Or
you could have a panel which contains these components and add it to each of the 3 panels that you show on your cardLayout.
Or
you could store the values selected in the components in globals to your class and replicate each of the components with this data in each of your three panels.

Similar Messages

  • How can I use the same object in the different jsp files?

    I am doing a project. I have finished my jave source files and compiled them successfully. And I also wrote a main method to test my classes, they also worked well. Now I am trying to use my jave code in the jsp files. But I meet a problem, in my method of java source file, I can generate a object of a class, and use it in the whole main method. But in the different jsp files, how can I do same thing?
    For example, in the .java file,
    Vector vl = new Vector();
    While ...{
    vl.add(...)
    In each of my .jsp file I want to do one loop of the above, meanwhile I want to do that in the same object.
    I hope you can understand what I mean. Really need your help!

    put your object into a session and you can the use it in all the jsps as long as the session is valid. Or you could create a static variable in the class that only creates one instance off an object and then create a static method to return this object.

  • Ultra slow imports?  This just started seemingly out of nowhere.  One day it works perfect and now it is so slow it is not useable. Tried different card reader with sam results.

    One day importing works great and now it is not even useable its so slow...what happened?  Any ideas?  I tried a different card reader...same results.  Tried different card...same results

    Ouch, tough spot, but offhand I'd say some memory may have gone bad, or maybe just needs re-seating after all this time.
    Not much you can do, but try this anyway...
    PRAM reset, CMD+Option+p+r...
    http://support.apple.com/kb/ht1379
    In fact, do 3 in a row, takes a bit of time.

  • IPhoto card layout

    I have iPhoto ver 9.4.3. I am trying to create a flat card but iphoto only alows me to use 4 different card layouts.
    Is there a way to modify the "standard" layouts or create new card layouts other than what iPhoto allows?

    Do you have iWork?  With Pages it's easy to create a collage of photos of any size you want. Just drag the photos from iPhoto onto the Pages layout, resize and place where you want Like this 20 x 30 poster with 96 photos:
    The demo version of OmniGraffle will let you create a layout with 10 photos on it.

  • I am trying to add a new credit card and it keeps telling me that I have to enter a valid security code...I have tried 2 different cards and it is doing the same thing. How do I get past this?

    I guess it has been a year since I last purchased something on I-tunes and my account is saying that they couldn't authorize my card for some of my purchases.  I am trying to add a new credit card to clear this up and it keeps saying that I have to enter a valid security code.  I have tried 2 different cards and I get the same thing.  I have also added an I-tunes gift card and that isn't clearing up the money that I owe.  It is showing that I have a $25 credit for that.  How do I fix this, I have been trying for days and all I have got from the e-mail tech support is that its my credit card issuer that is causing the problem.  Thats not correct because one of the credit cards that I am trying to use, is a prepaid Visa gift card.  I know that these work on I-tunes because I have used them before in the past.  I am getting very frustrated with this whole process, I just want to clear up my account and buy some new music!! HELP!!

    You probably ran into blocks & locks.
    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html
    They'll sort it out.

  • SSDT Schema Compare keeps showing the same objects as different..

    Hi, 
    When comparing a database to my project using Visual Studio 2012 SSDT I get several stored procedures marked as changed. The body of the procedures is identical, but two properties are highlighted as different when expanding the object:
    IsSelf (false on the DB vs true on the project) and User  (dbo on the DB, needs to be added to the project).
    The procedures have the option "with execute as self" both in the database and in the project as part of the body.
    I have not found what needs to be done so these differences are applied to the project and never appear again. Tried changing some options on the schema compare but didn't found one that help. 
    Some forum suggested dropping the objects and re-creating them but I don't want to loose the history of changes on TFS.
    Any suggestions? 

    Hi Daniel,
    Since you have posted this issue to the SSDT forum here:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5c9c5c47-64ac-4af4-9104-c9500dc8cf52/ssdt-schema-compare-keeps-showing-the-same-objects-as-different?forum=ssdt#5c9c5c47-64ac-4af4-9104-c9500dc8cf52
    I will move this thread to the Off-topic forum, thanks for your understanding.
    Sincerely,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • This sign appeared in my account: "Your payment method was declined. Update your biiling info'. After adding new information about my others cards I see the same sign. Can't understand what the problem is and what should I do. Need help!!!

    This sign appeared in my account: "Your payment method was declined. Update your biiling info'. After adding new information about my others cards I see the same sign. Can't understand what the problem is and what should I do. Everything used to be good before.
    Do anyone know what I supposed to do in that situation?
    Really need help!
    Thanks in advance.

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • My USB CF Card reader is not mounting on my 2.5 GHZ Intel Core i5 iMac anymore. It was last week and worked fine to get pictures from my camera. Now it won't mount. I have tried another card reader and the same problem exists. Also tried different cards..

    Hi
    My USB CF (Compact Flash) Card reader is not mounting on my 2.5 GHZ Intel Core i5 iMac anymore.
    Last week it worked fine to get pictures from my camera but now it won't mount at all.
    I ejected it in the correct way rather than just disconnecting it but now i cannot get it to remount!
    I cannot even see it in the disk utility or system profiler.
    I have tried another card reader (a brand new one bought today) and the same problem exists. I've also tried different cards to see if that made a difference and they still arent being picked up on the Mac. 
    I have done all the usual things like rebooting, unplugging all other USB devices and then trying but nothing has worked.
    I'm a photographer and I'm at my wits end here. I know the cards are fine as i have been using them without issue and they are also new.
    Note: If I plug the camera in directly to the Mac, the Mac picks it up just fine as it always has done. Its just the card readers that it wont pick up anymore.
    If anyone has any ideas at all other than the following (my so called friends advice) you'd earn my undting love:
    Buy a PC
    Use the camera (Thats why i bought the reader in the first place - importing RAW files from the camera is SLOW!)
    Replace your CF cards (I have three 8GB cards two of which i had never used til today and they dont work either!)
    Buy a new card reader (this is the 5th one in two days - none work on the Mac)
    Many thanks in advance!
    LIsa

    OK, restart in Safe Mode, this will clear some caches. It's possible one or more is corrupt. To restart in Safe Mode when you hear the start up tone hold down the Shift Key until you see a progress bar. Let it fully boot then restart normally and test.
    Also I am assuming you have checked Finder - Preferences  - General and see what boxes are checked in "Show these items on desktop." You can also mount an item in Disk Utility, simply highlight it and then look in the File menu for Mount.....

  • Accesing same object from different servlets

    Hello all!
    I am developing a web control project. I am using a simulator of a factory (with java). The engineers are supposed to be able to change some variables from the web.
    I am using servlets to change this variables. My problem is that, to be able to change variables, I need to create an instance of this FactorySimulator object.
    If each servlet ( there are many servlets) calls an instance, they will be updating different FactorySimulator objects.
    How can I make reference, or have acces to the SAME object, from any servlet?
    Thanks! I hope my question is clear =)

    package com.yourcompany.somepackage;
    public class TheFactory
        private static FactorySimulator factory = new FactorySimulator();
        private TheFactory() {} // Static methods only, do not instantiate TheFactory
        public FactorySimulator instance()
            return factory;
    }From each of your servlets you can call TheFactory.instance().doWhataver(). Methods in FactorySimulator need to be suitably synchronized of course.

  • No SIM on iPad. Tried different cards, same thing. Updated and multiple reboots have solved the problem. IPad fault?

    No Sim on iPad. Tried different cards, same thing. Updated iOS and multiple reboots, no luck. iPad fault? What do I do now, ask for replacement?

    Apple has acknowledged that the "no sim card" message has been a problem for some users. iOS 5.1 is reported by MacWorld to resolve this issue. 5.1 is in development and a beta version has been seeded to developers. In the meant time I suggest contacting Apple.

  • *How to Delet one same object from different roles*

    I need to delete one auth object from different roles, Couls any one please advise me how can i do this and if there will be any complications involved with tis.
    Best regards:
    Maq

    In PFCG, it may be that you have added some objects manually. To remove them you will have to go to pfcg.
    Even if you first remove the objects from su24, you will have to go to all the roles through pfcg to generate them in expert mode by selecting the third option (edit old status and merge with new data)

  • Multiple Transports included in different ChaRM tickets on same objects

    Hi Experts,
    We have ChaRM tickets created for different business CRs, and often a same object has to be changed for different CRs. A question is that is there a way of checking if an object is included in more than one different transports under different ChaRM tickets? How can we best organise the order of the ChaRM tickets so that there will not be a collision?
    Many thanks for your insights shared!
    BR Li Li

    Hi Experts,
    We have ChaRM tickets created for different business CRs, and often a same object has to be changed for different CRs. A question is that is there a way of checking if an object is included in more than one different transports under different ChaRM tickets? How can we best organise the order of the ChaRM tickets so that there will not be a collision?
    Many thanks for your insights shared!
    BR Li Li

  • Want to compare same object in different systems

    hi all,
    i want to compare same object in different systems
    example:
    same transfer rule in BID to be compared with the one in BIT/BIP
    in these kind of cases, pls help me on how to do the comparison.
    as i have to do some enhancement in BID and release that changes to BIT/P. but while manually checking i might also miss out any important changes which might create issues.
    pls suggest.

    Could you please use the below table for comparision.
    Cubes      RSDCUBE
    DSO's (to identify DSOu2019s based on time stamp field)     RSODSO
    Multiproviders     RSDCUBEMULTI
    Infosets     RSQISET
    Trasnformations      RSTRAN
    DTP's     RSBKDTP, RSBKDTPSTAT
    Trasnfer strcuture     RSTS
    Infopackages     RSLDPIO
    Update Rules     RSUPDINFO
    Aggregates     RSDAGGDIR/RSDAGGDIR
    Process Chians     RSPCCHAIN
    OHD's     
    data sources status      ROOSOURCE,RSDS
    Regards,
    Saveen Kumar

  • Provide a way to distinguish same object from different schema

    Hi there,
    When the same object is present in different schema and loaded into sql developer, there no chance to distinguish at first sight to which connection (or schema) the object belong.
    Example :
    DbConnection1 -> tables -> my_table
    DbConnection2 -> tables -> my_table
    when both are "loaded" (visible as a tab on the right side of sql developer)...i have no chance to find visually which "my_table" tab belong to "DbConnection1" or to "DbConnection2"...
    Regards,
    Pierre-Yves

    Thanks.
    A good idea would be to provide an option in "Preferences" to activate (or not) the display of the connection info directly in the tab name (my_table@dbConnection1).
    Regards,
    Pierre-Yves

  • Same object size (front panel) with different screen resolution

    Hi everybody,
    I realised an application, and I try to instal it on various computer. The probleme is that they haven't the same screen resolution, so the front panel is not the same on each computer. It is possible to build an application which have the same front panel with different screen resolution ?
    Kriss.

    Hi Krisss,
    switch off any "adapt to screen resolution" switches in the VI properties...
    You should also define "same front panel" and "same object size"! Do you mean the same pixel size or size in mm or size in percent of screen?
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

Maybe you are looking for