O.K. here comes a small example,
if you switch between Y-Axis and X-Axis
you see a difference. With Y-Axis all the buttons
have the same size (same width),
with X-Axis all the buttons do not have the same
height. The same behavior I do see when I compose
the GUI using the Swing Designer. I am looking for
a way to use the X-Axis BoxLayout for a sequence of
JToggleButtons where the buttons are allowed to have
different widths while having the exactly same height:
- Code: Select all
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_CLOSE);
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);
}
}