public class TEST extends JFrame{
    ... blah, blah.....
    private void launch(){
	setBounds(200, 200, 100, 100);
	JPanel greenPanel = new JPanel();
	greenPanel.setSize(70, 70); //<---- xNot resize the greenPanel
	JPanel yellowPanel = new JPanel();
	yellowPanel.setSize(50, 50); //<-- xNot resize yellowPanel in greenPanel
	JPanel bluePanel = new JPanel();

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:

Any ideas?

Recommended Answers

The default FlowLayout gives you very little control over component sizing/resizing behavior. Try a different layout manager to achieve the behavior that you want:

Jump to Post

All 2 Replies

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))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.