List of usage examples for javax.swing Box createGlue
public static Component createGlue()
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component1 = new JButton(); JButton component2 = new JButton(); Box box = new Box(BoxLayout.X_AXIS); box.add(component1);// w ww. j av a 2s. com box.add(Box.createGlue()); box.add(component2); }
From source file:GlueSample.java
public static void main(String args[]) { Box horizontalBox;//from www . j av a 2s .co m JPanel panel; JFrame frame = new JFrame("Horizontal Glue"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning Glue")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Middle")); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("2 Middle Glues")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); horizontalBox.add(Box.createGlue()); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning/End Glues")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); horizontalBox.add(Box.createGlue()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("End Glue")); contentPane.add(panel); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box left = Box.createVerticalBox(); left.add(Box.createVerticalStrut(30)); ButtonGroup radioGroup = new ButtonGroup(); JRadioButton rbutton;//from ww w. j a v a 2 s . c om radioGroup.add(rbutton = new JRadioButton("Red")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Green")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Blue")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Yellow")); left.add(rbutton); left.add(Box.createGlue()); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.add(left, BorderLayout.CENTER); Box right = Box.createVerticalBox(); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Dashed")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Thick")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Rounded")); right.add(Box.createGlue()); JPanel rightPanel = new JPanel(new BorderLayout()); rightPanel.add(right, BorderLayout.CENTER); Box top = Box.createHorizontalBox(); top.add(leftPanel); top.add(Box.createHorizontalStrut(5)); top.add(rightPanel); Container content = aWindow.getContentPane(); content.setLayout(new BorderLayout()); content.add(top, BorderLayout.CENTER); BoxLayout box = new BoxLayout(content, BoxLayout.Y_AXIS); content.setLayout(box); content.add(top); aWindow.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame aWindow = new JFrame("This is a Box Layout"); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box left = Box.createVerticalBox(); left.add(Box.createVerticalStrut(30)); ButtonGroup radioGroup = new ButtonGroup(); JRadioButton rbutton;/* w w w . j a v a2s. c om*/ radioGroup.add(rbutton = new JRadioButton("Red")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Green")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Blue")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Yellow")); left.add(rbutton); left.add(Box.createGlue()); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Color")); leftPanel.add(left, BorderLayout.CENTER); Box right = Box.createVerticalBox(); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Dashed")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Thick")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Rounded")); right.add(Box.createGlue()); JPanel rightPanel = new JPanel(new BorderLayout()); rightPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Properties")); rightPanel.add(right, BorderLayout.CENTER); Box top = Box.createHorizontalBox(); top.add(leftPanel); top.add(Box.createHorizontalStrut(5)); top.add(rightPanel); Container content = aWindow.getContentPane(); content.setLayout(new BorderLayout()); content.add(top, BorderLayout.CENTER); BoxLayout box = new BoxLayout(content, BoxLayout.Y_AXIS); content.setLayout(box); content.add(top); aWindow.setVisible(true); }
From source file:SimpleAboutDialog.java
public SimpleAboutDialog(JFrame parent) { super(parent, "About Dialog", true); Box b = Box.createVerticalBox(); b.add(Box.createGlue()); b.add(new JLabel("Java source code, product and article")); b.add(new JLabel("By Java source and support")); b.add(new JLabel("At www.java2s.com")); b.add(Box.createGlue());/*from www . java 2 s. co m*/ getContentPane().add(b, "Center"); JPanel p2 = new JPanel(); JButton ok = new JButton("Ok"); p2.add(ok); getContentPane().add(p2, "South"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { setVisible(false); } }); setSize(250, 150); }
From source file:Main.java
public Main() { JPanel holderPanel = new JPanel(new BorderLayout()); holderPanel.add(thumbPanel, BorderLayout.NORTH); holderPanel.add(Box.createGlue(), BorderLayout.CENTER); setLayout(new BorderLayout()); add(new JScrollPane(holderPanel), BorderLayout.CENTER); }
From source file:Main.java
public Main() { setPreferredSize(new Dimension(500, 500)); getContentPane().setLayout(new BorderLayout()); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(4, 4, 4, 4); panel.add(new JLabel("Label"), c); panel.add(new JTextField(20), c); c.gridwidth = GridBagConstraints.REMAINDER; panel.add(new JButton("btn"), c); c.gridwidth = 1;/*from w ww . j av a 2 s . c o m*/ panel.add(new JLabel("Name"), c); panel.add(new JTextField(20), c); c.gridwidth = GridBagConstraints.REMAINDER; panel.add(new JButton("btn"), c); c.weighty = 1.0; panel.add(Box.createGlue(), c); add(panel, BorderLayout.LINE_START); pack(); 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. ja v a 2 s. co m*/ 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:MainClass.java
public MainClass() { Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);//from www .j av a2 s.c o m JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:CommonLayouts.java
public CommonLayouts() { super("Common Layout Managers"); setSize(500, 380);/* www . ja va 2s.com*/ JPanel desktop = new JPanel(); getContentPane().add(desktop); JPanel fr1 = new JPanel(); fr1.setBorder(new TitledBorder("FlowLayout")); fr1.setLayout(new FlowLayout()); fr1.add(new JButton("1")); fr1.add(new JButton("2")); fr1.add(new JButton("3")); fr1.add(new JButton("4")); desktop.add(fr1, 0); JPanel fr2 = new JPanel(); fr2.setBorder(new TitledBorder("GridLayout")); fr2.setLayout(new GridLayout(2, 2)); fr2.add(new JButton("1")); fr2.add(new JButton("2")); fr2.add(new JButton("3")); fr2.add(new JButton("4")); desktop.add(fr2, 0); JPanel fr3 = new JPanel(); fr3.setBorder(new TitledBorder("BorderLayout")); fr3.add(new JButton("1"), BorderLayout.NORTH); fr3.add(new JButton("2"), BorderLayout.EAST); fr3.add(new JButton("3"), BorderLayout.SOUTH); fr3.add(new JButton("4"), BorderLayout.WEST); desktop.add(fr3, 0); JPanel fr4 = new JPanel(); fr4.setBorder(new TitledBorder("BoxLayout - X")); fr4.setLayout(new BoxLayout(fr4, BoxLayout.X_AXIS)); fr4.add(new JButton("1")); fr4.add(Box.createHorizontalStrut(12)); fr4.add(new JButton("2")); fr4.add(Box.createGlue()); fr4.add(new JButton("3")); fr4.add(Box.createHorizontalGlue()); fr4.add(new JButton("4")); desktop.add(fr4, 0); JPanel fr5 = new JPanel(); fr5.setBorder(new TitledBorder("BoxLayout - Y")); fr5.setLayout(new BoxLayout(fr5, BoxLayout.Y_AXIS)); fr5.add(new JButton("1")); fr5.add(Box.createVerticalStrut(10)); fr5.add(new JButton("2")); fr5.add(Box.createGlue()); fr5.add(new JButton("3")); fr5.add(Box.createVerticalGlue()); fr5.add(new JButton("4")); desktop.add(fr5, 0); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }