is there any way to set the width of the JFrame fixed, but height of the JFrame dynamic? For an example,
width = 1200
Height = will be based on number of elements
in other words
width = 1200
Height = pack()
please help!
is there any way to set the width of the JFrame fixed, but height of the JFrame dynamic? For an example,
width = 1200
Height = will be based on number of elements
in other words
width = 1200
Height = pack()
please help!
Use a constant for width and a variable for height, and then use the regular setPreferredSize method
You probably don't need this, but for future people looking at this thread, you could declare a width constant, and set min & max size of the frame.
setMinimumSize(new Dimension(WIDTH, 0));
setMaximumSize(new Dimension(WIDTH, Integer.MAX_VALUE));
setResizable(false);
Subsequent calls to pack() will enforce the width, but allow the height to be dynamically calculated.