Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By DarrylBurke
  • 1 Post By Bellyfish

Thread: CardLayout issues

  1. #1
    Bellyfish is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default CardLayout issues

    Im trying to create a cardLayout with multiple cards.
    I can switch between card 1 and 2 with no problems, but when i try to move from 2 to 3 it just returns me to 1.
    Am i missing something? can i only use cardLayout to switch between 2 panels?

    Below is relevant code if helps (im invoking the the methods in the relevant classes already):

    Java Code:
    cardLayout = new CardLayout();
    		cardPane = new JPanel();
    		this.add(cardPane);
    		cardPane.setPreferredSize(new Dimension(1000,1000));
    		cardPane.setLayout(cardLayout);
    		cardPane.setVisible(true);
    		
    		orderPane = new OrderPanel(this);
    		orderPane.setPreferredSize(new Dimension(1000,1000));
    		
    		totalPane = new TotalPanel(this);
    		totalPane.setPreferredSize(new Dimension(1000,1000));
    		
    		pizzaPane = new JPanel();
    		pizzaPane.setPreferredSize(new Dimension(850,600));
    		ham = new JButton("Ham");
    		pizzaPane.add(ham); 
    		
    		cardPane.add(totalPane,"1");
    		cardPane.add(orderPane,"2");
    		cardPane.add(pizzaPane,"3");
    		returnMain();
    
    public void newOrder(String customerName,Date date) {
    		orderPane.setCustomerName(customerName);
    		cardLayout.show(cardPane, "2");
    	}
    	
    	public void returnMain() {
    		cardLayout.show(cardPane, "1");
    	}
    
    	public void showPizzaPane() {
    		cardLayout.show(cardPane, "3");
    	}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: CardLayout issues

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: CardLayout issues

    I agree with Darryl. On cursory glance, your code looks good, and I don't see the cause for your problem based on this code.

  4. #4
    Bellyfish is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: CardLayout issues

    Well I followed your advice and made a demonstration to show this problem, but the demonstration worked :s.
    Ill have a go at re-writing my code in the same way as my demonstration.
    Thanks for the idea thought^^
    DarrylBurke likes this.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: CardLayout issues

    Quote Originally Posted by Bellyfish View Post
    Well I followed your advice and made a demonstration to show this problem, but the demonstration worked :s.
    That's how the SSCCE advice usually works for those who actually read the page and apply the principles :)

    Unfortunately, we see a lot of members who just glance at the SSCCE page (or not) and come back with more uncompilable snippets that don't show the problem.

    Feel free to come back if you have more questions (but now that you know about the SSCCE, you probably won't).

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. CardLayout with JPanels
    By Angelo in forum AWT / Swing
    Replies: 17
    Last Post: 12-15-2011, 06:50 PM
  2. CardLayout Help
    By David M. in forum New To Java
    Replies: 4
    Last Post: 08-06-2011, 02:57 AM
  3. CardLayout manager
    By abetemari in forum New To Java
    Replies: 4
    Last Post: 03-27-2011, 01:46 AM
  4. Help with CardLayout
    By Kyle227 in forum New To Java
    Replies: 4
    Last Post: 05-28-2010, 01:03 AM
  5. Regarding CardLayout
    By adeeb in forum AWT / Swing
    Replies: 1
    Last Post: 06-07-2008, 07:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •