List of usage examples for javax.swing BoxLayout Y_AXIS
int Y_AXIS
To view the source code for javax.swing BoxLayout Y_AXIS.
Click Source Link
From source file:BoxSample.java
public static void main(String args[]) { JButton button;//from www . j a va 2s .c o m Vector buttons = new Vector(); Dimension dim; JFrame frame = new JFrame("Box Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS)); JPanel topLeft = new JPanel(); topLeft.setLayout(new BoxLayout(topLeft, BoxLayout.X_AXIS)); topLeft.add(button = new JButton("One")); buttons.add(button); changeBoth(button); topLeft.add(button = new JButton("Two")); buttons.add(button); changeBoth(button); changeWidth(topLeft); JPanel bottomLeft = new JPanel(); bottomLeft.setLayout(new BoxLayout(bottomLeft, BoxLayout.X_AXIS)); bottomLeft.add(button = new JButton("Six")); buttons.add(button); changeBoth(button); bottomLeft.add(button = new JButton("Seven")); buttons.add(button); changeBoth(button); changeWidth(bottomLeft); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); left.add(topLeft); left.add(button = new JButton("Four")); buttons.add(button); changeBoth(button); left.add(bottomLeft); changeBoth(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); right.add(button = new JButton("Three")); buttons.add(button); changeWidth(button); right.add(button = new JButton("Five")); buttons.add(button); changeBoth(button); changeBoth(right); contentPane.add(left); contentPane.add(right); tweak(buttons); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea textArea = new JTextArea(10, 20); final JProgressBar progressBar = new JProgressBar(0, 10); final CounterTask task = new CounterTask(); task.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { progressBar.setValue((Integer) evt.getNewValue()); }//from w ww . j a va 2s . c o m } }); JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { task.execute(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { task.cancel(true); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(startButton); buttonPanel.add(cancelButton); JPanel cp = new JPanel(); LayoutManager layout = new BoxLayout(cp, BoxLayout.Y_AXIS); cp.setLayout(layout); cp.add(buttonPanel); cp.add(new JScrollPane(textArea)); cp.add(progressBar); JFrame frame = new JFrame("SwingWorker Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:PassiveTextField.java
public static void main(String[] args) { try {/*from w w w . j a va 2 s . c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Passive Text Field"); f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS)); final PassiveTextField ptf = new PassiveTextField(32); JTextField tf = new JTextField(32); JPanel p = new JPanel(); JButton b = new JButton("OK"); p.add(b); f.getContentPane().add(ptf); f.getContentPane().add(tf); f.getContentPane().add(p); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("Action event from a text field"); } }; ptf.addActionListener(l); tf.addActionListener(l); // Make the button the default button f.getRootPane().setDefaultButton(b); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("Content of text field: <" + ptf.getText() + ">"); } }); f.pack(); f.setVisible(true); }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
public static void main(String[] args) { JFrame frame = new JFrame("RedstoneLamp"); frame.setLayout(new GridLayout(2, 1)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel label = new JLabel("RedstoneLamp"); label.setHorizontalAlignment(SwingConstants.CENTER); frame.add(label);// www. jav a 2 s. c o m JPanel lowPanel = new JPanel(); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); lowPanel.add(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); lowPanel.add(right); JButton openButton = new JButton("Open server at..."); openButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Select RedstoneLamp server home"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showOpenDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (!jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. " + "Would you like to install RedstoneLamp there?"); if (result == JOptionPane.YES_OPTION) { installCallback(frame, selected); } return; } frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); } }); right.add(openButton); JButton installButton = new JButton("Install server at..."); installButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser("."); chooser.setDialogTitle("Select directory to install server in"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showSaveDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. " + "Are you sure you want to reinstall RedstoneLamp there?"); if (result == JOptionPane.NO_OPTION) { frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); return; } } installCallback(frame, selected); } }); frame.add(lowPanel); frame.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dimension.width / 2 - frame.getSize().width / 2, dimension.height / 2 - frame.getSize().height / 2); 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;/*w w w . ja v a 2s . co m*/ 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;/*from www . ja va2s . c o m*/ 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:URLMonitorPanel.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame("URL Monitor"); Container c = frame.getContentPane(); c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); Timer t = new Timer(); String[] u = new String[] { "http://www.java2s.com", "http://www.java2s.com" }; for (int i = 0; i < u.length; i++) { c.add(new URLMonitorPanel(u[i], t)); }/*from www . ja v a 2s.c o m*/ frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); frame.pack(); frame.show(); }
From source file:Main.java
private static JPanel createLogin() { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); JLabel label = new JLabel("login panel."); label.setFont(label.getFont().deriveFont(Font.ITALIC, 24f)); label.setAlignmentX(0.5f);//from w w w . ja va2 s . com label.setBorder(new EmptyBorder(0, 20, 0, 20)); p.add(Box.createVerticalStrut(36)); p.add(label); p.add(Box.createVerticalStrut(144)); return p; }
From source file:AlignX.java
private static Container makeIt(String labelChar, float alignment) { JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);/* w ww. j ava 2s . c o m*/ for (int i = 1; i < 6; i++) { String label = makeLabel(labelChar, i * 2); JButton button = new JButton(label); button.setAlignmentX(alignment); container.add(button); } return container; }
From source file:YAxisAlignX.java
private static Container makeIt(String title, float alignment) { String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); container.setBorder(BorderFactory.createTitledBorder(title)); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);/*from w w w.j a va2s .c o m*/ for (int i = 0, n = labels.length; i < n; i++) { JButton button = new JButton(labels[i]); button.setAlignmentX(alignment); container.add(button); } return container; }