#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    23
    Rep Power
    0

    Multiple java frames


    Hi i want to do something that sounds simple but it has been giving me a lot of problems. I want to display two panels inside of a jframe. So far none of the panels show up when i run the program. I can't figure out why at least one of them isn't showing up. here's the code thanks
    Code:
    import java.awt.*;
    import java.awt.BorderLayout.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    
    public class twoFrame extends JFrame
    {
    
    	private JFrame big;
    	private JPanel panel1, panel2;
    	private JButton but;
    	private JScrollPane sp;
    	private JTextArea full;
    
    	public twoFrame()
    	{
    		JFrame big = new JFrame();
    
    
    		full = new JTextArea();
    
    		sp = new JScrollPane(full);
    		sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    		sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    		full.setEditable(false);
    
    
    
    		JPanel panel1 = new JPanel();
    		getContentPane().add(panel1);
    		panel1.setPreferredSize(new Dimension (300,300));
    		panel1.setLayout(null);
    		//panel1.setBounds(10,10,300,300);
    		panel1.setVisible(true);
    
    		add(panel1);
    		panel1.add(sp);
    
    
    		JPanel panel2 = new JPanel();
    		getContentPane().add(panel2);
    		panel2.setLayout(null);
    
    
    		big.add(panel1);
    		big.add(panel2);
    		//panel2.add(but);
    		//big.add(but);
    		pack();
    
    		setTitle("Practice Frame");
    		setLocationRelativeTo(null);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setVisible(true);
    		this.setExtendedState(Frame.MAXIMIZED_BOTH);
    	}
    	public static void main(String[] args)
    	{
    		twoFrame tf = new twoFrame();
    	}
    
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    A couple of problems I notice. You are creating a new JFrame in the constructor of twoFrame, but you don't make it visible.

    Also the panels you create are added to the frame you don't make visible.

    Also since you remove the layout manager from panel1, you will have to explicitly set the size of the ScrollPane.

IMN logo majestic logo threadwatch logo seochat tools logo