0

https://i.stack.imgur.com/H7I80.jpg

In the picture black color is JFrame, cyan color is JPanel.

At first, I set JFrame size (500,500), and a JPanel whose width is the same as the JFrame width but whose height is 10 and it works well. When I increased the JFrame size as like monitor size, I want to increase JPanel size automatically, however JPanel width was not increased. What should I do? Or should I make JFrame.setResizable(false)?

camickr
  • 321,443
  • 19
  • 166
  • 288
MD SAJJAD
  • 3
  • 4
  • I suspect you meant [« responsive »](https://en.m.wikipedia.org/wiki/Responsive_web_design) – Basil Bourque Dec 10 '21 at 05:52
  • You could use some kind of proportional layout. `GridBagLayout` can do this, for [example](https://stackoverflow.com/questions/26922807/resizable-window-with-3-proportional-panels/26923195#26923195) or, if you're up for a challenge, you could always [roll your own](https://stackoverflow.com/questions/14635952/java-layout-proportions-creating-a-scalable-square-panel/14636828#14636828) – MadProgrammer Dec 10 '21 at 06:02
  • 1
    Create two `JPanels`. The first `JPanel` is your cyan `JPanel`. Set the preferred size to 500, 10. The second `JPanel` is your black `JPanel`. Set the preferred size to 500, 490. Place the cyan `JPanel` in the `JFrame` NORTH and place the black `JPanel` in the `JFrame` CENTER. Instead of setting the size of the `JFrame`, pack it. – Gilbert Le Blanc Dec 10 '21 at 08:31
  • Oracle has a helpful tutorial, [Creating a GUI With Swing](https://docs.oracle.com/javase/tutorial/uiswing/index.html). Skip the Netbeans section. – Gilbert Le Blanc Dec 10 '21 at 08:35

0 Answers0