I'm doing a prototype for showing some basic functions of a painting program. Now, here is how the window looks like:
The window is compound of a panel with a vertical BoxLayout, inside it, there are a custom image control and another panel with a FlowLayout containing all the buttons.
The problem is that I have to specify the height for the buttons panel (in 100px). If I delete that line, the window looks like this:
But, if I only specify the width, and I write a 0 for the height, I get this:
I want the layouts determine the correct height of the buttons panel by themselves. Here is the code that produces the first image:
public void createAndShowGui(){
JFrame.setDefaultLookAndFeelDecorated(true);
setTitle("SimplePaint");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
//Main container layout.
BoxLayout mainLayout = new BoxLayout(getContentPane(), BoxLayout.Y_AXIS);
getContentPane().setLayout(mainLayout);
drawingPanel = new JPanel();
drawingPanel.setLayout(null);
drawingPanel.setPreferredSize(new Dimension(width, height));
TextBox editor = new TextBox();
drawingPanel.add(editor);
editor.setVisible(false);
canvasControl = new DrawableCanvas(editor);
drawingPanel.add(canvasControl);
canvasControl.setBounds(0, 0, width, height);
getContentPane().add(drawingPanel);
drawingSurface = canvasControl.getDrawingSurface();
//Buttons layout.
FlowLayout buttonsLayout = new FlowLayout();
JPanel buttonsPanel = new JPanel(buttonsLayout);
buttonsPanel.setPreferredSize(new Dimension(width, 100)); // <-- Not in this way
//Buttons creation...
pack();
}
Thanks in advance.