Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: displaying multiple jpanels in a jframe

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default displaying multiple jpanels in a jframe

    hi, is it possible to display another jpanel in the frame instead of opening a new frame each time?


    public void actionPerformed(ActionEvent e)
    {
    JFrame aFrame = new JFrame();
    aFrame.setBounds(0,0,400,600);
    Container contentPane = aFrame.getContentPane();
    JButton s = (JButton)e.getSource();
    if(s == attack)
    {
    contentPane.add(new Attack());
    }
    else if(s == defense)
    {
    contentPane.add(new Defense());
    }
    aFrame.setVisible(true);

    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,180
    My Mood
    Hungover
    Thanks
    141
    Thanked 601 Times in 516 Posts

    Default Re: displaying multiple jpanels in a jframe

    Did you not like the answer I gave you in your other post?

    Crossposted: adding multiple jpanels to content pane - Java Forums
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Resizing JPanels in JScrollPanes
    By aussiemcgr in forum AWT / Java Swing
    Replies: 4
    Last Post: November 29th, 2010, 01:13 PM
  2. Not Displaying what I need
    By rob3097 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 7th, 2010, 09:31 PM
  3. swing - switching JPanels
    By bbr201 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 5th, 2010, 09:18 AM
  4. [SOLVED] Dynamic numbber of JPanels
    By nasi in forum AWT / Java Swing
    Replies: 2
    Last Post: May 14th, 2010, 02:44 AM
  5. repainting a jframe containing two jpanels
    By musasabi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 11th, 2010, 10:31 PM

Tags for this Thread