List of usage examples for javax.swing Box createHorizontalBox
public static Box createHorizontalBox()
Box
that displays its components from left to right. From source file:HBoxWithGlue.java
public HBoxWithGlue() { super("Box & Glue Frame"); setSize(350, 100);// ww w .j a v a2s . c om Box box = Box.createHorizontalBox(); setContentPane(box); box.add(Box.createHorizontalGlue()); for (int i = 0; i < 3; i++) { Button b = new Button("B" + i); box.add(b); } box.add(Box.createHorizontalGlue()); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); }
From source file:HBoxWithStrut.java
public HBoxWithStrut() { super("Box & Strut Frame"); setSize(370, 80);/* ww w .j a v a2 s .c o m*/ Box box = Box.createHorizontalBox(); setContentPane(box); for (int i = 0; i < 3; i++) { Button b = new Button("B" + i); box.add(b); } // Add a spacer between the first three buttons and the last three box.add(Box.createHorizontalStrut(10)); for (int i = 3; i < 6; i++) { Button b = new Button("B" + i); box.add(b); } setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); }
From source file:Main.java
public Main() { super("Demostrating BoxLayout"); final int SIZE = 3; Container c = getContentPane(); c.setLayout(new BorderLayout(30, 30)); Box boxes[] = new Box[4]; boxes[0] = Box.createHorizontalBox(); boxes[1] = Box.createVerticalBox(); boxes[2] = Box.createHorizontalBox(); boxes[3] = Box.createVerticalBox(); for (int i = 0; i < SIZE; i++) boxes[0].add(new JButton("boxes[0]: " + i)); for (int i = 0; i < SIZE; i++) { boxes[1].add(Box.createVerticalStrut(25)); boxes[1].add(new JButton("boxes[1]: " + i)); }// w ww . j a v a 2 s .c om for (int i = 0; i < SIZE; i++) { boxes[2].add(Box.createHorizontalGlue()); boxes[2].add(new JButton("boxes[2]: " + i)); } for (int i = 0; i < SIZE; i++) { boxes[3].add(Box.createRigidArea(new Dimension(12, 8))); boxes[3].add(new JButton("boxes[3]: " + i)); } JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); for (int i = 0; i < SIZE; i++) { panel.add(Box.createGlue()); panel.add(new JButton("panel: " + i)); } c.add(boxes[0], BorderLayout.NORTH); c.add(boxes[1], BorderLayout.EAST); c.add(boxes[2], BorderLayout.SOUTH); c.add(boxes[3], BorderLayout.WEST); c.add(panel, BorderLayout.CENTER); setSize(350, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:Box1.java
public void init() { Box bv = Box.createVerticalBox(); for (int i = 0; i < 5; i++) bv.add(new JButton("bv " + i)); Box bh = Box.createHorizontalBox(); for (int i = 0; i < 5; i++) bh.add(new JButton("bh " + i)); Container cp = getContentPane(); cp.add(BorderLayout.EAST, bv); cp.add(BorderLayout.SOUTH, bh); }
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);//w ww .ja va 2s . c om getContentPane().add(bv); }
From source file:Main.java
public void init() { Box bv = Box.createVerticalBox(); bv.add(new JLabel("Hello")); bv.add(Box.createVerticalGlue()); bv.add(new JLabel("Applet")); bv.add(Box.createVerticalGlue()); bv.add(new JLabel("World")); Box bh = Box.createHorizontalBox(); bh.add(new JLabel("Hello")); bh.add(Box.createHorizontalGlue()); bh.add(new JLabel("Applet")); bh.add(Box.createHorizontalGlue()); bh.add(new JLabel("World")); bv.add(Box.createVerticalGlue()); bv.add(bh);/*from w w w. j a v a 2 s. co m*/ bv.add(Box.createVerticalGlue()); getContentPane().add(bv); }
From source file:Box2.java
public void init() { Box bv = Box.createVerticalBox(); for (int i = 0; i < 5; i++) { bv.add(new JButton("bv " + i)); bv.add(Box.createVerticalStrut(i * 10)); }//from ww w . jav a2 s .co m Box bh = Box.createHorizontalBox(); for (int i = 0; i < 5; i++) { bh.add(new JButton("bh " + i)); bh.add(Box.createHorizontalStrut(i * 10)); } Container cp = getContentPane(); cp.add(BorderLayout.EAST, bv); cp.add(BorderLayout.SOUTH, bh); }
From source file:Main.java
private Box getEditPaneBox() { editorPane.setEditable(false);//from ww w.j a v a 2 s . c om Box editorBox = Box.createHorizontalBox(); editorBox.add(new JScrollPane(editorPane)); editorPane.addHyperlinkListener((HyperlinkEvent event) -> { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { go(event.getURL()); } else if (event.getEventType() == HyperlinkEvent.EventType.ENTERED) { System.out.println("click this link"); } else if (event.getEventType() == HyperlinkEvent.EventType.EXITED) { System.out.println("Ready"); } }); editorPane.addPropertyChangeListener((PropertyChangeEvent e) -> { String propertyName = e.getPropertyName(); if (propertyName.equalsIgnoreCase("page")) { URL url = editorPane.getPage(); System.out.println(url.toExternalForm()); } }); return editorBox; }
From source file:RasterDemo.java
public RasterDemo() { super();//from w w w .jav a 2s . c o m Container container = getContentPane(); displayPanel = new RasterPanel(); container.add(displayPanel); Box box = Box.createHorizontalBox(); flipButton = new JToggleButton("Flip the Image"); flipButton.addActionListener(new ButtonListener()); box.add(Box.createHorizontalGlue()); box.add(flipButton); box.add(Box.createHorizontalGlue()); container.add(box, BorderLayout.SOUTH); addWindowListener(new WindowEventHandler()); setSize(450, 400); show(); }
From source file:Main.java
public Main() { for (int i = 0; i < 15; i++) { ((DefaultListModel<String>) sourceList.getModel()).add(i, "A " + i); ((DefaultListModel<String>) destList.getModel()).add(i, "B " + i); }//from ww w . j a v a2 s. c o m Box nameBox = Box.createHorizontalBox(); nameBox.add(new JLabel("New:")); nameBox.add(newTextField); Box sourceBox = Box.createVerticalBox(); sourceBox.add(new JLabel("Source")); sourceBox.add(new JScrollPane(sourceList)); Box destBox = Box.createVerticalBox(); destBox.add(new JLabel("Destination")); destBox.add(new JScrollPane(destList)); Box listBox = Box.createHorizontalBox(); listBox.add(sourceBox); listBox.add(destBox); Box allBox = Box.createVerticalBox(); allBox.add(nameBox); allBox.add(listBox); this.getContentPane().add(allBox, BorderLayout.CENTER); sourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); destList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); newTextField.setDragEnabled(true); sourceList.setDragEnabled(true); destList.setDragEnabled(true); sourceList.setDropMode(DropMode.INSERT); destList.setDropMode(DropMode.INSERT); sourceList.setTransferHandler(new ListTransferHandler()); destList.setTransferHandler(new ListTransferHandler()); }