Swapping one panel for another

Hi
I have a frame that creates a panel with a JLabel when the program is first run. On this frame I have another panel that has a button "next" on it. When the button is clicked, i want the panel with the label to disappear and be replaced by a new panel, but i dont know how to implement this. Both of the panels that change are in separate classes that extend JPanel. If anyone knows how to do this then and can provide some code then that would be most appreciated and very helpful.
Thanks

You should look at using a CardLayout in java.awt.
CardLayout mainLayout = new CardLayout();
JPanel mainPanel = new JPanel(mainLayout);
mainPanel.add("first", your1stPanel);
mainPanel.add("next", otherPanel); //add takes a string (a name) and a component that
//and associates that string with the component
and then to show the intial panel you call
mainLayout.show("first") //show takes the string you used to name the component
and then when they press the "next" button you call
mainLayout.show("next")
You can even cycle through Your Components by using next() and previous check out the CardLayout API.

Similar Messages

  • Gradual swap one bitmap for another?

    I am trying to swap one bitmap for another over a few
    seconds. I can't get it to work. Is this a motion tween or shape
    tween or what?

    newbie1420,
    > Sorry about the delay, I would like to "morph" one photo
    into
    > another, one fades into the next.
    It sounds like you're using two words to describe the same
    technique --
    but I'm not sure. To me, a morph is when one raster image
    slowly
    metamorphoses into another. If photo A is a dog, and photo B
    is a cat, the
    area that represents the dog's nose literally changes shape
    to become the
    shape of a cat's nose The dog's ears may grow, warp, or
    otherwise distort
    to become the shape of the cat's ears, and so on. Fading
    generally
    describes a dissolve: nothing in either image changes shape;
    it's just that
    one image slowly becomes more transparent, revealing the
    image beneath it.
    > I have made them into movie clip symbols, still not
    getting the right
    > effect...
    If you're after morphing, as described above, you'll find
    that Flash
    doesn't support it. If you're after a dissolve, you can
    achieve the effect
    easily by putting two photos into their own symbols, as
    you've done, and
    each symbol in its own layer, one atop the other. Put two
    keyframes in the
    upper symbol. At the first keyframe, make sure the symbol's
    Alpha property
    is 100. At the second keyframe, make sure the symbol's Alpha
    property is 0.
    Motion tween the span of frames between those two keyframes,
    and you'll have
    your dissolve, aka fade.
    David Stiller
    Co-author, Foundation Flash CS3 for Designers
    http://tinyurl.com/2k29mj
    "Luck is the residue of good design."

  • How do I swap one clip for another in Final Cut Pro 7?

    How do I sway one clip for another in Final Cut Pro 7? I am doing what it says in a book but it is not working. Thanks.

    You drag the clip from the browser to the clip on the timeline. Wait till the timeline clip goes white. Drop it and pick from the menu that appears the replace option you want.

  • How to call repaint() from one panel for another panel

    I have two classes (leftPanel and rightPanel), which extends JPanel. I have added these panels to the container of the JFrame. I have a JButton in my left leftPanel. When I click the button I want that the repaint method of rightPanel is called. Please tell me how to do that.

    Ok, the reason it wasn't working is because the two classes don't have a reference to each other. They don't have anything in common at all. The only class hooking them together is the myFrame. Therefore, myFrame is the class that should be the communication link. I've added a few lines of code to myFrame, but didn't change the other classes. Now myFrame has an actionListener and it listens for the leftPanel.leftButton. When the leftButton fires, myFrame tells rightPanel to repaint. Another cool way would be to have an actionListener on rightPanel and register that with leftPanel when you instantiate them in myFrame.
    GL
    kimoS
    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import java.util.*;
    public class myFrame extends JFrame implements ActionListener{
    leftPanel left;
    rightPanel right;
    static int st=0;
    myFrame(){
    left=new leftPanel();
    left.leftButton.addActionListener(this);
    right=new rightPanel();
    this.getContentPane().add(left,BorderLayout.WEST);
    this.getContentPane().add(right,BorderLayout.CENTER);
    public static void main(String args[]){
    myFrame mf=new myFrame();
    mf.setSize(500,500);
    mf.setVisible(true);
    public void actionPerformed(ActionEvent e){
    right.repaint();
    class leftPanel extends JPanel {
    JButton leftButton;
    leftPanel(){
    leftButton=new JButton("leftButton");
    this.add(leftButton);
    leftButton.addActionListener(new leftButtonListener());
    class leftButtonListener implements ActionListener{
    public void actionPerformed(ActionEvent e){
    myFrame.st=myFrame.st+1;
    System.out.println("st value inside listener="+myFrame.st);
    // ??? here I want to call repaint method of rightPanel
    class rightPanel extends JPanel{
    int flag=-1;
    public void paintComponent(Graphics g) {
    update(g);
    public void update(Graphics g){
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.drawString("If " myFrame.st" increases then repaint() called on click of button",30,100);
    flag=flag*(-1);
    if(flag==1){
    g2.drawString(" painting is working",100,200);
    }

  • Change one colour for another.

    Quite simply I'd like to swap one colour for another: maybe to turn all black into red and leave the rest as it is...or select greens only and make them blue. I've found various ways to adjust and alter colours but usually the entire picture is altered not just one element of it (eg., Enhance > color > Hue/saturation) . I'm using Pshop LE but I think this would be a universal feature...can't seem to find it though! Hope you can suggest something...

    Most forums wouldn't accept a reply four years later, but the information sure helped me four years later. Henrik said:
    What about Enhance > Adjust Color > Replace Color, is that tool available in PS LE?
    It's available Photoshop Elements 6.0 and it totally did the job for me. Someone had scanned some text for me and a lot of the background was grey. In only two operations, I changed one colour grey background to white (actually maximum lightness) and the remaining colour grey to white. I didn't know there really was such a feature, just that I wanted there to be that feature, and I don't know that I'd ever have guessed where to find it. It took me about 3 minutes total to find the forums and find this answer and do what I wanted. Am I ever happy. Thanks for the information.

  • How to exchange one image for another with a click

    I am brand new to actionscript, so bear with me! I need to create an interactive web-based system which takes the user through steps to assemble something. One of the pages will have images of the tools needed. I want the user to be able to 'tick' off each tool, so that when they click on the image of a specific tool it is replaced by the image faded out and a big red tick over it. essentially it is replacing one image for another when it is clicked on.
    any ideas on the actionscript? Sorry i know this must be basic stuff for you!
    thanks!

    your tool images should be converted to movieclips and given instance names and you should create a red tick movieclip that you assign a class, say RedTick.  you can then use:
    tool1.addEventListener(MouseEvent.CLICK,toolClickF);
    function toolClickF(e:MouseEvent):void{
    var redtick:RedTick=new RedTick();
    addChild(redtick);
    redtick.x=e.currentTarget.x;
    redtick.y=e.currentTarget.y;
    e.currentTarget.alpha=.4;

  • How do I drag an image icon or image from one panel to another panel?

    Please help.
    I know to need how to drag an image icon from one panel to the other. For example, the first panel would shows the image files that is inside my folder. How can i code it so that I can drag the image that appear on the first panel into the second panel which will hold the images that I want to embed my barcode inside?
    The thumbnail size of the image and showing all the image files in my folder was done already, I only need to know how can I make the image icon to be able to drag from one panel to the other.
    Thanks.

    I found this code in some websites:
    public class ImageSelection extends TransferHandler {
         private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
         public int getSourceActions(JComponent c) {
              return TransferHandler.COPY;
         public boolean canImport(JComponent comp, DataFlavor flavor[]){
              if (!(comp instanceof JLabel)){
                   return false;
              for (int i=0, n=flavor.length; i<n; i++){
                   for (int j=0, m=flavors.length; j<m; j++){
                        if (flavor.equals(flavors[j])){
                             return true;
              return false;
         public Transferable createTransferable(JComponent comp) {
              if (comp instanceof JLabel) {
                   JLabel label = (JLabel)comp;
                   Icon icon = label.getIcon();
                   if (icon instanceof ImageIcon){
                        final Image image = ((ImageIcon)icon).getImage();
                        final JLabel source = label;
                        Transferable transferable = new Transferable(){
                             public Object getTransferData(DataFlavor flavor){
                                  if (isDataFlavorSupported(flavor)){
                                       return image;
                                  return null;
                             public DataFlavor[] getTransferDataFlavors(){
                                  return flavors;
                             public boolean isDataFlavorSupported(DataFlavor flavor){
                                  return flavor.equals(DataFlavor.imageFlavor);
                        return transferable;
              return null;
         public boolean importData(JComponent comp, Transferable t){
              if (comp instanceof JLabel){
                   JLabel label = (JLabel)comp;
                   if (t.isDataFlavorSupported(flavors[0])){
                        try {
                             Image image = (Image)t.getTransferData(flavors[0]);
                             ImageIcon icon = new ImageIcon(image);
                             label.setIcon(icon);
                             return true;
                        catch (UnsupportedFlavorException ignored){
                        catch (IOException ignored) {
              return false;
    What this codes does is to get the image from the imageicon and replace the image to the imageicon that you drag the source from. However, I had no clue how I can get the source's file name. Anyone can teach me how?
    Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Passing parameter from one panel to another

    Hi guys, I'm working on an html5 extension, I have one main panel and then a second one that I open using the requestOpenExtension(). One problem I've ran into is I need to pass a parameter e.g. a number or a string from the 1st panel to that 2nd one when I request it. I noticed the StartupParams in the requestOpenExtension function, but I couldn't find any information at all about how it works or how to retrieve the parameter once the extension is open, or if I can even use it for custom parameters
    Would love any help with this, as its quite an important issue for me
    Cheers

    Hi,
    reading the commented code:
    * Loads and launches another extension, or activates the extension if it is already loaded.
    * @param extensionId       The extension's unique identifier.
    * @param startupParams     Not currently used, pass "".
    * @example
    * To launch the extension "help" with ID "HLP" from this extension, call:
    * <code>requestOpenExtension("HLP", ""); </code>
    CSInterface.prototype.requestOpenExtension = function(extensionId, params)
        window.__adobe_cep__.requestOpenExtension(extensionId, params);
    it looks like the startupParams aren't implemented yet.
    I hope to be wrong ;-)
    Regards
    Davide Barranca
    www.davidebarranca.com
    www.cs-extensions.com

  • How can I load the mix of one song for another song?

    I'm going to be mixing a live gospel album with 9 tracks of drums, bass, guitar, piano, strings, organ, lead vocals and 6 tracks of choir vocals. Each song will basically be mixed the same except for variations in the choir levels and lead vocals. I want to mix this in logic but I don't want to create a mix for each song from scratch. All the audio tracks will be consistiently on the same track, meaning Bass-trak 1, guitar-trak 10 etc... for each song. What would be the easiest way to do this without creating a mix from scratch for each song.
    Thanks

    Hi. I find myself in this situation a lot, and eventually settled on this method.
    Mix the first track the way you want it, and getting your levels and plugins settled. Save the song as the title of that particular song. Then, select everything in the arrange window, and delete it. If you are asked to delete or keep audio files, click keep, cos you don't want to lose recorded audio. If you have set markers, delete those too. if you have any automation, select track automation>delete all automation of all tracks.
    You are then set with a clean sheet with your tracks labelled, levels set and all the bells and whistles. Now do a SAVE AS and call it something like KICKASSGOSPELTEMPLATE or even save it as a logic template. Then, with this template open, open up another one of your songs, select everything in your arrange window, copy it to your clipboard, move to your template song, go bar number 1, and paste. You will be asked whether you want to copy instruments or tracks. I can't remember which one you select, but a quick trial and error should see you straight. All the audio tracks should come down onto the right audio objects and hitting play should have you almost to where you want to be.

  • Moving canvas3d from one panel to another panel is causing problems

    Hi,
    I'm new to java3d and at present struggling to find a solution for the following problem:
    In my application there are 4 canvas3ds and there are no relation between them except they all share the same screen3d. added in a Jpanel using grid layout(2,2). all have different universe. when user double click s any one of them the clicked canvas is supposed to get maximized and again doing the same restores everything before double click.
    What i'm doing is using card layout adding two panels one for normal view(4 at a time) and one for maximized view. The first one uses grid and the other one uses border.
    In case of maiximizing i just remove the one that's clicked from the former jpanel and add it to the other panel.But some times it garbles the screen in a way such that on rotating any node or element moves other nodes that are not supposed to be.
    Any suggestions???

    well you should have posted in java3d forum, but at this point i'd say post code so we can see what you mean by "garbles"

  • HT4859 I am unable to recover a rented movie after changing one iPad for another. Music and books were easily restored

    I am unable to restore a rented movie after Changing out my iPad for a new one. All music and books were restored easily

    PS - have found other posts indicating that clips smaller than 2s or sometimes 5s, or "short files" can cause this. Modern style editing often uses short takes ! Good grief I cannot believe Apple. Well I deleted a half a dozen short sections and can export, but now of course the video is a ruined piiece of junk and I need to re-do the whole thing, the sound etc. which is basically taking as much time as the original. And each time I re-do it I risk again this lovely error -50 and again trying to figure out what thing bugs it via trial and error instead of a REASONABLE ERROR MESSAGE POINTING TO THE CLIP IT CAN'T PROCESS. What a mess. I HATE this iMovie application - full of BUGS BUGS BUGS which Apple will not fix obviously, since I had this product for a few years and see just hundreds of hits on Google about this error with disappointed users. Such junk I cannot believe I paid money for it and Apple does not support it with fixes !!!
    If anyone knows of a GOOD reasonably priced video editing program NOT from APPLE I am still looking for suggestions. I want to do more video in future, but obviously NOT with iMovie !!!

  • Using the Template of one site for another site.

    Hi,
    I have created and published Site A using a template (DW CS4).  I now wish to create Site B and use the same template from the Site A.
    The only thing which will change is the banner which I create in Photoshop for each site.
    I also wish to use the navigation buttons which were part of Site A's template. Can this be done?
    One note: all the files from Site A have been copied into Site B.
    Any help is greatly appreciated.
    Frank

    One note: all the files from Site A have been copied into Site B.
    Including the template? If so, then blast ahead. Things should work fine.

  • Exchanging one router for another

     i currently have a working WRT54G2 router and will be swapping it for a e1200 router. Should I disconnect the current router from the modem first before inserting the setup CD for the new router? Thanks for any help on this issue.

    Well, yes if you are using the new E1200 router you have to remove the old Router WRT54G from the network.  For the initial setup, all it requires is a proper physical connectivity between your modem, router and computer.  To setup a new router, it’s always recommended to set the router to factory defaults before you run the CD. Finally run the Cisco connect software that’s bundled with the CD, which handles both your internet setup and wireless setup. For the setup process, you need to perform the following:
           i.    Verify that there is an active Internet connection between the computer and modem
          ii.   Setting up the router using Cisco Connect
    For more information about installing the E1200 router via Cisco Connect. Please refer to the link below.
    http://www6.nohold.net/Cisco2/ukp.aspx?vw=1&docid=e30f926604334d538668529cb50ad174_21463.xml&pid=80&...

  • Post items from one account for another new account

    Hi people,
    We would like to know if there is some procedure do post all of the documents we have in a specific account to a new one. (document by document).
    Thanks,
    Rosana.

    Hi,
    Based on Area we have diffrent process.
    Ex:
    GL Posting " Document Type SA, Post Key 40 & 50 Etc.
    Vendor " Document Type KA,KR,KZ Post Key 25, 29 & 31 Etc.
    Customer " Doc Type DA,DR,DZ Post key * 01,09,15,19* Etc
    Asset: Document Type "AA, Post key 70 &75 Etc
    Like same based on process we have diffrent T.Codes.
    Regards
    Viswa

  • Can I substitute one class for another at run time

    In one compilation unit, there are 2 classes. One is public.(class Test is public and class Process is without any modifier. Test is inherited from Process). There is a private method in Process. When i try to compile while accessing the private method of Process in Test, I get a compiler error, rightfully so. But I successfully got a Process.class.
    So, now i remove the private access modifier from my method in Process class and compile the whole thing and am able to run (java Test). But, if i replace the latest Process.class with the original Process class with the private method, I am still able to run(java Test)!!
    This all happed in Windows NT but not in Solaris.
    Is this correct ? Is this not a security violation?

    It's a bug: http://developer.java.sun.com/developer/bugParade/bugs/4293149.html

Maybe you are looking for

  • ITunes won't open (this isn't an idiot question)

    When I first got my iPod mini, I set everything up the way I wanted it and iTunes would open every time I plugged my iPod in. It was beautiful. Now, even though I didn't change anything to my knowledge, iTunes won't open when I plug my iPod into my c

  • Any danes who can explain what this is about.

    Got this message from controlling the disc.... Kontrollerer enheden "Macintosh HD" Kontrollerer HFS Plus-enhed. Kontrollerer Extents Overflow-arkiv. Kontrollerer katalogarkiv. Kontrollerer arkiver med mange forbindelser. Kontrollerer kataloghierarkie

  • Non-Apple keyboard and Target display mode?

    Hi, How do I change to Target Display Mode with a Logitech keyboard? The usual Command/Windows + f2wont work! edit: what would be perfect is an applescript to do this, anybody ever heard of one?

  • Automatically Delete Troubled Files

    You know those stupid files that have those stupid exclamation marks next to them is there a way to simply delete those without having to click multiple times on the song and manually do it?

  • How can I constrain proportions when resizing a crop?

    the questions in the title folks! thanks in advance... Or is there a better way to do this...I am adding some simulated camera shake to my shot, now black shows top or bottom when it is shaking, hence I need to zoom in to prevent the viewer seeing th