List of usage examples for javax.swing JButton setAlignmentX
@BeanProperty(description = "The preferred horizontal alignment of the component.") public void setAlignmentX(float alignmentX)
From source file:Main.java
public static void main(String[] argv) { JFrame f = new JFrame(); f.setLayout(new BorderLayout()); JPanel panel = new JPanel(); JButton button = new JButton("A-ha!"); button.setAlignmentX(Component.CENTER_ALIGNMENT); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.add(Box.createVerticalGlue()); panel.add(button);/*from ww w.j a va 2 s .c om*/ panel.add(Box.createVerticalGlue()); f.getContentPane().add(panel); f.setVisible(true); }
From source file:BoxLayoutYAXISTest.java
public static void main(String[] args) { JFrame f = new JFrame("Vertical BoxLayout-managed container"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); for (float align = 0.0f; align <= 1.0f; align += 0.25f) { JButton button = new JButton("X Alignment = " + align); button.setAlignmentX(align); pane.add(button);// w ww. j a v a 2s . c om } f.setSize(400, 300); f.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS); container.setLayout(layout);//from w w w . j a v a 2s .c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.BOTTOM_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);//from w w w . j a v a 2 s . c om for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.LEFT_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS); container.setLayout(layout);//from ww w . ja v a2 s. c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.TOP_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);//from ww w . j av a 2 s .co m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.CENTER_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);//w w w.j a v a2s. c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(Component.RIGHT_ALIGNMENT); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createLineBorder(Color.RED)); BoxLayout mgr = new BoxLayout(panel, BoxLayout.Y_AXIS); panel.setLayout(mgr);/* ww w . jav a2s . com*/ for (int i = 0; i < 5; i++) { JButton button = new JButton("Remove Hello World " + (i + 1)); button.setAlignmentX(Component.CENTER_ALIGNMENT); button.addActionListener(e -> { panel.remove(button); panel.revalidate(); panel.repaint(); }); panel.add(button); } frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:BoxLayoutVerticalGlueTest.java
public static void main(String[] args) { JFrame f = new JFrame("Vertical BoxLayout-managed container"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = new BoxPanel(); f.setContentPane(pane);//from w ww . j a v a 2s .com pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); for (float align = 0.0f; align <= 1.0f; align += 0.25f) { JButton button = new JButton("X Alignment = " + align); button.setAlignmentX(align); pane.add(button); pane.add(Box.createVerticalGlue()); } f.setSize(400, 300); f.setVisible(true); }
From source file:VerticalBoxLayoutManagerContainerTest.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = new BoxPanel(); f.setContentPane(pane);//from www . ja v a 2s . c om BoxLayout bl = new BoxLayout(pane, BoxLayout.Y_AXIS); pane.setLayout(bl); for (float align = 0.0f; align <= 1.0f; align += 0.25f) { JButton button = new JButton("X Alignment = " + align); button.setAlignmentX(align); pane.add(button); pane.add(Box.createRigidArea(new Dimension(0, 15))); } f.setSize(400, 300); f.setVisible(true); }