Replacing existing panel with a new panel.

I don't use swing much and I have ran into a small problem.
What is the standard procedure for replacing a jpanel on a
jframe with another jpanel in the exact same position?
Say you had a form on the first panel, when the user clicks
next it display a new panel with a confirmation of the results
and disposes of the old one.
I have tried add,remove, setcontenpane. setvisible etc but nothing
works. Can someone explain?
Here is a small app which demonstrates my problem:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class FrameTest extends JFrame implements ActionListener{
     JPanel jp1;
     JPanel jp2;
     JButton jb1;
     JButton jb2;
     public FrameTest(String name) {
          super(name);
          init();
     public void init() {
          jp1 = new JPanel(new FlowLayout());
          jb1 = new JButton("One");
          jb1.addActionListener(this);
          jp1.add(jb1);
          setContentPane(jp1);
          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          setBounds(0, 0, 200, 200);
          setVisible(true);
     public JPanel panelTwo() {
          jp2 = new JPanel(new FlowLayout());
          jb2 = new JButton("Two");
          jb2.addActionListener(this);
          jp2.add(jb2);
          return jp2;
     public static void main(String[] args) {
          FrameTest ft = new FrameTest("Test");
      * On click I wish to replace panel one
      * with panel two
     public void actionPerformed(ActionEvent e) {
               //What can I add here?
}Regards

I just took a look on the Java Tutorial and it is exactly what I am after.
Thank you.

Similar Messages

  • Replace existing footage with new footage, while keeping chapter markers ?

    I have prepared my DVD with menus and chapter markers etc ready for burn.
    I just noticed that my edit is wrong. Is their a way to replace exiting edit with the new one ? while maintaining chapter markers ?
    Thanks in advance.

    Replacing content like that almost always results in problems trying to encode/multiplex the project. You need to start a new project and reinsert your chapter marks. Sorry.

  • My one year warranty expired recently, a month ago my charger was replaced under warranty and it has only lasted a month and has broken again, does the replacement charger come with a new warranty or will i have to buy a new one?

    Bought the phone on contract last January (late in january), had my charger replaced just after christmas and now it has stopped working again, its been about a month and a half and the replacement charger is broken, does the replacement charger come with a new warranty or will I have to buy a new charger? And if so, is there a charger that doesn't break easily (my problem is the the wire at the phone end of the cable seems to bunch and twist etc.)
    thanks.

    a warranty replacement if the donor is out of warranty has a new 90 days warranty from exchange date 

  • Since i got the new Iphone 4s it constantly drops calls. Apple have replaced the phone with another new iphone 4s but i am still having the same problem. I have checked with vodapohe that there is no issue from there end, given a new sim, still drops out

    Since i got the new Iphone 4s it constantly drops calls. Apple have replaced the phone with another new iphone 4s but i am still having the same problem. I have checked with vodapohe that there is no issue from there end, given a new sim, still drops out

    Have a look at this it might help
    http://support.apple.com/kb/TS4148

  • Do I have all the parts to replace my HDD with a new SSD on my Macbook (late 2008)?

    Hey everyone, I am trying to figure out if have all the parts to replace my hdd with a new ssd on my macbook (late 2008 aluminum).
    I just bought a crucial mx100 SSD and plan on replacing my mac HDD. I have the appropriate screwdrivers, and a bootable OSX on a usb drive. I also purchased a sabrent usb 2.0 to sata/ide hard drive adapter.
    How do I replace and install OSX on my new SSD?
    From what I read here are the steps I'm planning on taking.
    1) Detach the old HDD
    2) Attach new SSD.
    3) Turn on computer and use the bootable usb drive to install OS X.
    Does that work, I think I read somewhere about maybe formatting the SSD before I can use the bootable usb. Any input or help would be awesome. Thanks.
    I'd prefer to do a clean install of yosemite and not carbon copy my old HDD

    Hi Bradtk24,
    On this site you will find the requirements for the physical change that you want to make.
    These pages will give you insight into the processes required for the software side of things. It might be slightly dated, but the principles remain valid.
    Have fun
    Leo

  • [AS] CS3- Find any text with style, then replace that text with a new applied fill color.

    I am trying to find the simplest way in cs3 to find any text with style, then replace that text with a new fill color. I can find text and change text. I can find a style and change it to a new style. I can't seem to find a style and change the applied fill color. I do not want to change the properties of the style, just the applied color. Yes, I want the + sign, for now. I know, why not update the style, I am not allowed to. Any help would be great. Since the search is not available, I need a new response.
    Thanks.

    You can work around the bug by just doing a find, then looping through the<br />results, changing the color one at a time. It'll be a fraction slower, but<br />should do the trick:<br /><br />tell application "Adobe InDesign CS3"<br />    set find text preferences to nothing<br />    set properties of find text preferences to {applied paragraph style:"The<br />name"}<br />    set theFinds to find text document 1<br />    repeat with i from 1 to count of theFinds<br />        set properties of item i of theFinds to {fill color:"Replace color"}<br />    end repeat<br />end tell<br /><br />The bug is fixed in CS4, BTW.<br /><br />-- <br />Shane Stanley <[email protected]><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>

  • Mail in Mavericks not replacing existing mail with same name

    Mail in Mavericks not replacing existing mail with same name.
    Thanks

    I have the same situation as you - sending out pdfs of designed pages and wanting to overwrite them continually. It used to happen on an older version of Mail, then it disappeared and now it's back with the latest version.
    It's more than annoying, it's downright driving me nuts. In the last hour I had to quit Mail seven times.
    Please send a fix for this Apple.

  • How do i replace an asset with a newer version?

    let's say i have an asset which is a Photoshop file, filename "v1". i want to replace the asset with a newer version of the Photoshop file, filename "v2".
    how do i replace the "v1" asset with the "v2" asset, so that all instances of "v1" in the project are changed to "v2"?
    thank you.
    rev B 20" iMac G5   Mac OS X (10.4.2)  

    let's say i have an asset which is a Photoshop file,
    filename "v1". i want to replace the asset with a
    newer version of the Photoshop file, filename "v2".
    how do i replace the "v1" asset with the "v2" asset,
    so that all instances of "v1" in the project are
    changed to "v2"?
    thank you.
    rev B 20"
    iMac G5 Mac OS X (10.4.2)
    I usually just write over the file with the same file name, often with DVDSP closed.
    If you're doing an m2v file and the duration has changed, just go the the end of the clip in the track and drag it right as far as you can. Otherwise it'll replace the asset but use the previous version's duration.
    G5 Dual 2GHz   Mac OS X (10.4.4)  

  • How do I replace the organiser with a new one

    How do I replace the organiser with a new one

    The problem is to understand your question (or your two questions : do you both mean the same thing ?)
    An answer to Hatstead question would help.
    1 - Do you really mean using another software to organize your workflow ?
    2 - Do you mean using other softwares based on folders rather than databases ?
    3 - Or do you mean working with different catalogs ?
    If you don't want to use the Organizer, it's not possible to 'delete' it, but it is simple not to use it.
    Most other organizing solutions include the choice of selecting PSE editor as the external editor
    There are various solutions depending on your platform : Windows, Mac, Linux...
    It's important to know if you prefer the folders or database organization to suggest possible solutions.

  • Replacing T420s HDD with a new SSD

    Hello,
    I wonderd if It is possible to replace the HDD with a new SSD, while placing the HDD in the Ultra-Bay slot.
    And if so, which SSD model should I buy, and how do I transfer the Operation System and data to the SSD?
    Will this SSD model be compatible?
    Corsair Neutron Series 120GB SSD Sata III MLC 2.5 Inch Retail
    Thank you so much,
    Guy
    Solved!
    Go to Solution.

    Corsair Force Series 3 Notebook Update Kit 120GB SATA III(6Gb/s) SSD Details :
    WarrantyThree years
    SSD Unformatted Capacity120 GB
    Max Sequential R/W (ATTO)550 MB/s sequential read — 510 MB/s sequential write
    Max Random 4k Write (IOMeter 08)85k IOPS (4k aligned)
    InterfaceSATA 6Gb/s
    TechnologyAsynchronous NAND
    Form Factor 7mm high, 2.5 inch
    DRAM Cache Memory No
    Weight80g
    Voltage5V ±5%
    Power Consumption (active)2.0W Max
    Power Consumption (idle/standby/sleep)0.5W Max
    S.M.A.R.T. SupportYes
    Shock1500 G
    MTBF2,000,000 hours
    Neutron Series 120GB SSD :
    WarrantyFive years
    SSD Unformatted Capacity120 GB
    Max Sequential R/W (ATTO)555 MB/s sequential read — 211 MB/s sequential write
    Max Random 4k Write (IOMeter 08)85k IOPS (4k aligned)
    InterfaceSATA 6Gb/s
    TechnologyNo
    Form Factor2.5 inch
    DRAM Cache MemoryNo
    Weight.1kg
    Voltage5V ±5%
    Power Consumption (active)4.6W Max
    Power Consumption (idle/standby/sleep)0.6W Max
    S.M.A.R.T. SupportYes
    Shock1500 G
    MTBF2,000,000 hours
    T420s 4170-CTO : i5 2520M, 6GB RAM, 320GB HDD(7200rpm).
    Z60t 2513-MCU.

  • How can I replace the Portal with completely new Flash website?

    Can I replace the Portal with completely new Flash website? My customer do not want the JSP UI. Instead, he wants a completely new designed Flash site. Is it possible to do it? How can I deploy a new portal to cover the current one?

    If you have a look at some of the code examples which do the equivalent of site maps, you could in theory replace the whole portal desktop with some sort of Flash framework which reads the user's role structure at run time.
    I think it is useful to remember that the SAP portal is primarily a business application launchpad. It does that very well. Trying to make it into a Flash launchpad will be challenging.

  • My iphone has fallen into the water 6months ago and there is no apple store in my country so i gave the phone s technical service.but they couldnt repair the phone.and now the battery is swollen.can i replace the phone with the new one in spain?

    My iphone has fallen into the water 6months ago and there is no apple store in my country so i gave the phone s technical service.but they couldnt repair the phone.and now the battery is swollen.can i replace the phone with the new one in spain?

    You can only obtain warranty OR post warranty service in the country of original purchase
    As your iPhone has user damage it has no warranty
    IF the iPhone originated from Spain or another EU country you can get out of warranty service in any EU country

  • I have cs5.5 master collection. Replaced my iMac with a new one, used migration assistant, now on the new iMac the apps will not open,

    I have cs5.5 master collection. Replaced my iMac with a new one, used migration assistant, now on the new iMac the apps will not open,

    I found that out, so used the dvd install disk w the key and tried to install, ran to 87% complete then told me to close,
    safari
    safarinotificati
    i closed safari, still wouldn't finish loading, i closed all safari notifications, nope, can't find any app called safarinotificati
    New iMac, 10.10.2, photoshop ran perfectly on my old iMac with 10.10.2
    so I cannot complete the loading,
    John

  • TS4062 I replaced my iPad with a new one. I backed up to iCloud but did not do a physical iTune Sync. Now I am having trouble recovering some Notes and Photos. I have been reinstalling Apps from the App Store. How do I recover my Notes?

    I replaced my iPad with a new one. I backed up to iCloud but did not do a physical iTune Sync. Now I am having trouble recovering some Notes and Photos. I have been reinstalling Apps from the App Store. How do I recover my Notes?

    Thank you again for all of your help!! I really appreciate it!
    I think I am following -- I was able to upload to my iPhoto and all photos and videos are there that is a plus! I tried to create an Event in my iPhoto and put all of my photos in that event but for some reason, now my iTunes it not recognizing that Event in my iPhoto. It is not allowing me to import just that event at the moment but I may be doing something wrong. At least all of my pics and vids are in iPhoto so that is a plus and I know they are at least saved somewhere. Just for some reason, my iTunes it not locating the event that I created with only those photos.
    Thank you for letting me know about my contacts! How do I know if I have the contacts app?
    Also, I had no clue that my iCloud could be backed up via cellular data! However, is this a new feature with the most updated iOS?? Unforutnatly I am like 2 iOS updates behind because I don't have enough storage on my phone. I still get the notification that my phone needs to be plugged in and connected to wifi in order to back up to the cloud :-(
    How can I sync using USB? Right now when i click on the info tab for my iPhone in my iTunes this is the answer that I get -- I am a little unclear as to what it means.
    Sync Contacts:
    Your contacts are being synced with you iPhone over the air from iCloud. Over-the-air sync settings can be changed on you iPhone
    Sync Calendars:
    Your calendars are being synced with you iPhone over the air from iCloud. Over-the-air sync settings can be changed on you iPhone

  • Replace ipad mini with a newer version

    I got my 2nd ipad mini replacement from apple service center here in the Philippines last January 31, 2014. Technically this is my 3rd ipad mini (from the 1st that i bought to the 1st and 2nd replacement). After two weeks of use i noticed that it has also the same defects as with my 1st ipad mini replacement. (What is the odd of having 3 defective ipad minis?!) Apple service center here replace defective ipad mini with brand new one instead of repairing the product if and only if the defects is caused by hardware problems. I am planning to take this back to apple service center. My question is, is it possible to replace my ipad mini with the newer version? (i am very sure that they will still replace this with a new one.) Their price difference is just about Php5,000. I can just add for their price difference.

    let's say i have an asset which is a Photoshop file,
    filename "v1". i want to replace the asset with a
    newer version of the Photoshop file, filename "v2".
    how do i replace the "v1" asset with the "v2" asset,
    so that all instances of "v1" in the project are
    changed to "v2"?
    thank you.
    rev B 20"
    iMac G5 Mac OS X (10.4.2)
    I usually just write over the file with the same file name, often with DVDSP closed.
    If you're doing an m2v file and the duration has changed, just go the the end of the clip in the track and drag it right as far as you can. Otherwise it'll replace the asset but use the previous version's duration.
    G5 Dual 2GHz   Mac OS X (10.4.4)  

Maybe you are looking for