List of usage examples for javax.swing Box createRigidArea
public static Component createRigidArea(Dimension d)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Frame"); frame.add(Box.createRigidArea(new Dimension(400, 300))); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();//from w w w . j a v a 2 s . co m frame.setVisible(true); JDialog dialog = new JDialog(frame, "Dialog", true); int condition = JPanel.WHEN_IN_FOCUSED_WINDOW; InputMap inputMap = ((JPanel) dialog.getContentPane()).getInputMap(condition); ActionMap actionMap = ((JPanel) dialog.getContentPane()).getActionMap(); String enter = "enter"; inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), enter); actionMap.put(enter, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); dialog.add(Box.createRigidArea(new Dimension(200, 200))); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = new Box(BoxLayout.Y_AXIS); rowOne.add(new JLabel("Username")); rowOne.add(Box.createRigidArea(new Dimension(20, 20))); rowOne.add(new JTextField()); Component rowTwo = Box.createVerticalStrut(2); f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);//from w ww . j a va 2 s.co m f.setVisible(true); }
From source file:RigidArea.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setBorder(new EmptyBorder(new Insets(40, 60, 40, 60))); panel.add(new JButton("Button")); panel.add(Box.createRigidArea(new Dimension(0, 5))); panel.add(new JButton("Button")); panel.add(Box.createRigidArea(new Dimension(0, 5))); panel.add(new JButton("Button")); panel.add(Box.createRigidArea(new Dimension(0, 5))); panel.add(new JButton("Button")); JFrame f = new JFrame(); f.add(panel);// w w w. j av a2 s .co m f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame1 = new JFrame(); frame1.setExtendedState(JFrame.MAXIMIZED_BOTH); frame1.setUndecorated(true);/*from ww w . j a va 2s . c om*/ frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setVisible(true); JDialog nonModalDialog = new JDialog(frame1, "Non-Modal Dialog", ModalityType.MODELESS); nonModalDialog.add(Box.createRigidArea(new Dimension(200, 200))); nonModalDialog.pack(); nonModalDialog.setVisible(true); JDialog modalDialog = new JDialog(frame1, "Modal Dialog", ModalityType.APPLICATION_MODAL); modalDialog.add(Box.createRigidArea(new Dimension(200, 200))); modalDialog.pack(); modalDialog.setVisible(true); }
From source file:TwoButtons.java
public static void main(String[] args) { JFrame f = new JFrame(); JPanel basic = new JPanel(); basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS)); f.add(basic);// w ww.ja v a 2 s . c om basic.add(Box.createVerticalGlue()); JPanel bottom = new JPanel(); bottom.setAlignmentX(1f); bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS)); JButton ok = new JButton("OK"); JButton close = new JButton("Close"); bottom.add(ok); bottom.add(Box.createRigidArea(new Dimension(5, 0))); bottom.add(close); bottom.add(Box.createRigidArea(new Dimension(15, 0))); basic.add(bottom); basic.add(Box.createRigidArea(new Dimension(0, 15))); f.setSize(300, 250); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 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);/* w w w. j av a 2s . c o m*/ 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); }
From source file:Main.java
/** Creates a <code>width</code> x <code>height</code> rigid spacer. */ public static Component createRigidSpacer(final int width, final int height) { return Box.createRigidArea(new Dimension(width, height)); }
From source file:Main.java
public void init() { Box bv = Box.createVerticalBox(); bv.add(new JButton("Top")); bv.add(Box.createRigidArea(new Dimension(120, 90))); bv.add(new JButton("Bottom")); Box bh = Box.createHorizontalBox(); bh.add(new JButton("Left")); bh.add(Box.createRigidArea(new Dimension(160, 80))); bh.add(new JButton("Right")); bv.add(bh);//from w w w. j av a2s . c om getContentPane().add(bv); }
From source file:AboutDialog.java
public AboutDialog() { setTitle("About"); setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); add(Box.createRigidArea(new Dimension(0, 10))); JLabel name = new JLabel("Notes"); name.setAlignmentX(0.5f);// w w w.j ava2 s . c o m add(name); add(Box.createRigidArea(new Dimension(0, 100))); JButton close = new JButton("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dispose(); } }); close.setAlignmentX(0.5f); add(close); setModalityType(ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(300, 200); }
From source file:Main.java
public JPanel createUI() { intro.setLabelFor(name);// w w w . jav a2s.c o m final JButton button = new JButton("Pick a new name..."); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20)); intro.setAlignmentX(JComponent.CENTER_ALIGNMENT); name.setAlignmentX(JComponent.CENTER_ALIGNMENT); button.setAlignmentX(JComponent.CENTER_ALIGNMENT); panel.add(intro); panel.add(Box.createVerticalStrut(5)); panel.add(name); panel.add(Box.createRigidArea(new Dimension(150, 10))); panel.add(button); return panel; }