BoxLayout
:Box.createVerticalGlue()
methodBox.createHorizontalGlue()
methodJFrame f = new JFrame("test"); Container pane = f.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); JPanel xpane = new JPanel(); pane.add(xpane); xpane.setLayout(new BoxLayout(xpane, BoxLayout.X_AXIS)); xpane.add(Box.createHorizontalStrut(5)); xpane.add(new JFileSelector()); xpane.add(Box.createHorizontalStrut(5)); xpane.add(Box.createHorizontalGlue()); pane.add(Box.createVerticalStrut(5)); xpane = new JPanel(); pane.add(xpane); xpane.setLayout(new BoxLayout(xpane, BoxLayout.X_AXIS)); xpane.add(Box.createHorizontalStrut(5)); xpane.add(new JButton("Click Me!")); xpane.add(Box.createHorizontalGlue()); pane.add(Box.createVerticalGlue()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400, 300); f.setVisible(true);
JFrame f = new JFrame("test"); Container pane = f.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); JPanel xpane = new JPanel(); pane.add(xpane); xpane.setLayout(new BoxLayout(xpane, BoxLayout.X_AXIS)); xpane.add(Box.createHorizontalStrut(5)); xpane.add(new JFileSelector()); xpane.add(Box.createHorizontalStrut(5)); xpane.add(Box.createHorizontalGlue()); pane.add(Box.createVerticalStrut(5)); xpane = new JPanel(); pane.add(xpane); xpane.setLayout(new BoxLayout(xpane, BoxLayout.X_AXIS)); xpane.add(Box.createHorizontalStrut(5)); xpane.add(new JButton("Click Me!")); xpane.add(Box.createHorizontalGlue()); pane.add(LayoutUtils.createGreedyVerticalGlue()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400, 300); f.setVisible(true);We have the following result:
Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences