0

I want to increase the height of a custom JPanel in a JFrame. I tried to use pa.setSize(700,200) but it does not change anything.

Here is the code:

JFrame f = new JFrame("Hello");
f.setResizable(true);
JPanel pa = new JPanel();
JButton btn = new JButton("Exit");

pa.setBackground(Color.red);
pa.setSize(700, 200);

f.setUndecorated(true);
f.getContentPane().add(pa, BorderLayout.NORTH);
f.setSize(new Dimension(700,700));
f.setLocation(500, 500);
f.setVisible(true);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
tester7281
  • 13
  • 2
  • 2
    1- Use a layout manager which would support the `preferredSize` property; 2- Override the `getPreferredSize` method of the `JPanel` to return a size you'd prefer; – MadProgrammer Dec 31 '17 at 03:15
  • hey its you again, thank you so much for the help bro. it works – tester7281 Dec 31 '17 at 03:23

1 Answers1

0

its very simple solution instead of pa.setsize() change it into pa.setPreferredSize(new Dimension(width,60));

tester7281
  • 13
  • 2
  • See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) – Andrew Thompson Dec 31 '17 at 07:19