0
public class TEST extends JFrame{
    ... blah, blah.....
	
    private void launch(){
	setBounds(200, 200, 100, 100);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	
	JPanel greenPanel = new JPanel();
	greenPanel.setSize(70, 70); //<---- xNot resize the greenPanel
	greenPanel.setBackground(Color.green);
	
	JPanel yellowPanel = new JPanel();
	yellowPanel.setSize(50, 50); //<-- xNot resize yellowPanel in greenPanel
	yellowPanel.setBackground(Color.yellow);
	greenPanel.add(yellowPanel);
	
	JPanel bluePanel = new JPanel();
	bluePanel.setBackground(Color.blue);
	bluePanel.add(greenPanel);
	
	add(bluePanel);
	
	setVisible(true);
    }
}

So, I have a yellow JPanel inside a green JPanel inside a blue JPanel.. For some reason, none of the JPanels resize, only the JFrame...

Here's a picture:
http://img225.imageshack.us/img225/5460/jpanelbashsn7.png

Any ideas?

3
Contributors
2
Replies
9
Views
9 Years
Discussion Span
Last Post by Azeerazly
0

First of all, I want to say thanks! I had hard time doing JPanel over JPanel and in such colourful box.

change your setSize into setPreferredSize(new Dimension(int length, int width))

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.