Dear Folks,
I do have an issue with the Java BoxLayout Manager.
if I use BoxLayout with Y-Axis all buttons within a JPanel
are as wide as their container, in other words have the same width.
if I use BoxLaout with X-Axis orientation all buttons within a JPanel
are not as wide as thier container, in other words have different hights.
Here a small example, switch the commented line:
import java.awt.Component;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.BoxLayout;
public class SameHight {
public static void main( String args[] ) {
JFrame frame = new JFrame("Box Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
Container contentPane = frame.getContentPane();
JPanel panel = new JPanel();
// panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ));
panel.setLayout( new BoxLayout( panel, BoxLayout.X_AXIS ));
contentPane.add(panel);
JButton b1 = new JButton("<html><body>Button 1</html></body>");
panel.add(b1);
JButton b2 = new JButton("<html><body>Button 2<br>Spring Water</html></body>");
panel.add(b2);
JButton b3 = new JButton("<html><body>Button 3</html></body>");
panel.add(b3);
JButton b4 = new JButton("<html><body>Button 4<br>Fountain Water</html></body>");
panel.add(b4);
JButton b5 = new JButton("<html><body>Button 5</html></body>");
panel.add(b5);
JButton b6 = new JButton("<html><body>Button 6<br>Moutain Spring Water</html></body>");
panel.add(b6);
frame.pack();
frame.setVisible(true);
}
}