List of usage examples for javax.swing BoxLayout BoxLayout
@ConstructorProperties({ "target", "axis" }) public BoxLayout(Container target, int axis)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel controlPane = new JPanel(); JPanel buttonPane = new JPanel(); controlPane.setLayout(new BoxLayout(controlPane, BoxLayout.PAGE_AXIS)); controlPane.setPreferredSize(new Dimension(200, 200)); controlPane.add(new JScrollPane(new JTextArea())); buttonPane.setLayout(new FlowLayout(FlowLayout.LEFT)); buttonPane.setPreferredSize(new Dimension(100, 40)); buttonPane.add(new JButton("Button1")); buttonPane.add(new JButton("Button2")); frame.add(controlPane, BorderLayout.NORTH); frame.add(buttonPane, BorderLayout.SOUTH); frame.pack();/*w w w . ja v a 2 s . c o m*/ frame.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 w w w. jav a2s . 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:BoxLayoutManagerContainerTest.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 w w .ja v a2 s . co m*/ pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); for (float align = 0.0f; align <= 1.0f; align += 0.25f) { JTextField tf = new JTextField("X Alignment = " + align, 10); tf.setAlignmentX(align); pane.add(tf); } f.setSize(400, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { final JTextField textField = new JTextField(); JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); BoundedRangeModel brm = textField.getHorizontalVisibility(); scrollBar.setModel(brm);/*from ww w. j ava 2 s .c om*/ panel.add(textField); panel.add(scrollBar); textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Text: " + textField.getText()); } }); JFrame frame = new JFrame("Text Slider"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel, BorderLayout.NORTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int ROWS = 100; JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(new JLabel("Thanks for helping out. Use tab to move around.")); for (int i = 0; i < ROWS; i++) { JTextField field = new JTextField("" + i); field.setName("field#" + i); content.add(field);/*from ww w . jav a 2 s. c o m*/ } KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!(evt.getNewValue() instanceof JComponent)) { return; } JViewport viewport = (JViewport) content.getParent(); JComponent focused = (JComponent) evt.getNewValue(); if (content.isAncestorOf(focused)) { Rectangle rect = focused.getBounds(); Rectangle r2 = viewport.getVisibleRect(); content.scrollRectToVisible( new Rectangle(rect.x, rect.y, (int) r2.getWidth(), (int) r2.getHeight())); } } }); JFrame window = new JFrame(); window.setContentPane(new JScrollPane(content)); window.setSize(200, 200); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextField textField = new JTextField(); JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); BoundedRangeModel brm = textField.getHorizontalVisibility(); scrollBar.setModel(brm);/*w w w.j a v a 2 s. c o m*/ panel.add(textField); panel.add(scrollBar); frame.add(panel, BorderLayout.NORTH); frame.setSize(300, 100); 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 w w . java2 s . c o m 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:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;//from w w w . j av a 2 s. com JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); label = new JLabel("Raw Number:"); input = new JFormattedTextField(2424.50); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*ww w.j a v a 2s .c om*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); label = new JLabel("Raw Number:"); input = new JFormattedTextField(2424.50); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:MaskInputSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;//from w w w . j a v a 2 s . co m JFormattedTextField input; JPanel panel; MaskFormatter formatter; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); try { label = new JLabel("SSN"); formatter = new MaskFormatter("###'-##'-####"); input = new JFormattedTextField(formatter); input.setValue("123-45-6789"); input.setColumns(20); panel = new JPanel(); panel.add(label); panel.add(input); frame.add(panel); } catch (ParseException e) { System.err.println("Unable to add SSN"); } frame.pack(); frame.setVisible(true); }