I have a JPanel using a FlowLayout layout manager and contains components with different sizes.
EDIT: I want to use the FlowLayout because it allows the components to wrap to a new line when the container is resized and they no longer fit next to each other.
The following image depicts the vertical alignment of the FlowLayout on the different components:
How can I modify the FlowLayout to align the top of components as depicted in the following image:
Here is a code example of the problem:
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel flowPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
frame.getContentPane().add(flowPanel);
JButton firstComp = new JButton("First");
firstComp.setPreferredSize(new Dimension(200, 300));
flowPanel.add(firstComp);
JButton secondComp = new JButton("Second");
secondComp.setPreferredSize(new Dimension(160, 180));
flowPanel.add(secondComp);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);