In following code I have set background color the content pane of the JFrame
to black and JPanel
to red. But when I am trying to setSize()
with different sizes, red area does not contract or expend why is it so?
import java.awt.*;
import javax.swing.*;
public class exp{
public static void main(String args[]){
JFrame jf=new JFrame("This is JFrame");
JPanel h=new JPanel();
h.setSize(400,500);
h.add(new JButton("Button"));
h.add(new JLabel("this is JLabel"));
h.setBackground(Color.RED);
jf.add(h);
jf.getContentPane().setBackground(Color.BLACK);
jf.setLayout(new FlowLayout());
jf.setVisible(true);
jf.setSize(600,800);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}