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:Main.java
public TabPanel() { JPanel innerPanel = new JPanel(); innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS)); int USER_INPUT = 10; for (int i = 0; i < USER_INPUT; i++) { JPanel p = new JPanel(new BorderLayout()); JLabel label = new JLabel("Label" + i); JTextField textArea = new JTextField(); p.add(label, BorderLayout.NORTH); p.add(textArea, BorderLayout.CENTER); innerPanel.add(p);/*from w w w.jav a2s. co m*/ } JScrollPane scrollPane = new JScrollPane(innerPanel); scrollPane.setPreferredSize(new Dimension(400, 200)); this.add(scrollPane); }
From source file:Main.java
public Main() { super(BoxLayout.Y_AXIS); glassPane.setOpaque(false);//from w ww . j a v a 2 s.c o m DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); for (int i = 0; i < 14000; i++) { DefaultMutableTreeNode node = new DefaultMutableTreeNode("Root" + i); node.add(new DefaultMutableTreeNode("Child" + i)); root.add(node); } final JTree tree = new JTree(root); tree.setRootVisible(false); final JScrollPane pane = new JScrollPane(tree); add(pane); JButton button = new JButton("Expand"); button.addActionListener(e -> { Thread t = new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } TreePath[] paths = tree.getSelectionPaths(); if (paths == null || paths.length == 0) { glassPane.setVisible(false); return; } tree.setSelectionPath(paths[0]); for (int i = 0; i < paths.length; i++) { tree.expandPath(paths[i]); } glassPane.setVisible(false); } }); getRootPane().setGlassPane(glassPane); glassPane.setVisible(true); t.start(); }); add(button); glassPane.addMouseWheelListener(e -> { for (MouseWheelListener mwl : pane.getMouseWheelListeners()) { mwl.mouseWheelMoved(e); } }); }
From source file:layout.BoxLayoutDemo.java
public static void addComponentsToPane(Container pane) { pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); addAButton("Button 1", pane); addAButton("Button 2", pane); addAButton("Button 3", pane); addAButton("Long-Named Button 4", pane); addAButton("5", pane); }
From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java
public ColorPreferences(Component parent) { _parent = parent;/* w w w .j av a 2s. com*/ setBorder(new EmptyBorder(10, 10, 10, 10)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel pickers = new JPanel(); pickers.setLayout(new GridLayout(10, 2)); pickers.add(new Label(Messages.t("preferences.color.scheme.current.label"))); _comboBox = createSchemeCombobox(); pickers.add(_comboBox); addColorChooser(pickers, "gates"); addColorChooser(pickers, "background"); addColorChooser(pickers, "bus-on"); addColorChooser(pickers, "ground"); addColorChooser(pickers, "off"); addColorChooser(pickers, "wires-on"); addColorChooser(pickers, "signal"); addColorChooser(pickers, "grid"); addColorChooser(pickers, "label"); add(pickers); JPanel buttons = new JPanel(); JButton button = new JButton(Messages.t("preferences.color.scheme.save.label")); buttons.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { FileUtils.writeStringToFile(new File("colors.json"), ColorScheme.save()); } catch (IOException e1) { e1.printStackTrace(); } } }); button = new JButton(Messages.t("preferences.color.scheme.new.label")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String themeName = JOptionPane.showInputDialog(Messages.t("color.scheme.dialog.new.title"), ""); if (themeName != null) { while (ColorScheme.exists(themeName)) { JOptionPane.showMessageDialog(_parent, Messages.t("color.scheme.dialog.already.exists.error"), "Error", JOptionPane.ERROR_MESSAGE); themeName = JOptionPane.showInputDialog(this, themeName); } ColorScheme.add(themeName); _comboBox.addItem(themeName); _comboBox.setSelectedItem(themeName); } } }); buttons.add(button); add(buttons); }
From source file:SelectionMonitor.java
public SelectionMonitor() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); // Format the list and the buttons in a vertical box Box rightBox = new Box(BoxLayout.Y_AXIS); Box leftBox = new Box(BoxLayout.Y_AXIS); // Monitor all list selections list.addListSelectionListener(new RadioUpdater()); for (int i = 0; i < label.length; i++) { checks[i] = new JCheckBox("Selection " + i); checks[i].setEnabled(false);/*from w w w .j ava 2s . c om*/ rightBox.add(checks[i]); } leftBox.add(pane); add(rightBox, BorderLayout.EAST); add(leftBox, BorderLayout.WEST); }
From source file:SysConfig.java
public SysConfig() { super("JTabbedPane & BoxLayout Demonstration"); setSize(500, 300);//from ww w .j av a 2 s.c o m setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel configPane = new JPanel(); configPane.setLayout(new BoxLayout(configPane, BoxLayout.Y_AXIS)); JTextArea question = new JTextArea("Which of the following options\n" + "do you have installed?"); // Ok, now configure the textarea to show up properly inside the box. // This is part of the "high art" of Swing... question.setEditable(false); question.setMaximumSize(new Dimension(300, 50)); question.setAlignmentX(0.0f); question.setBackground(configPane.getBackground()); JCheckBox audioCB = new JCheckBox("Sound Card", true); JCheckBox nicCB = new JCheckBox("Ethernet Card", true); JCheckBox tvCB = new JCheckBox("Video Out", false); configPane.add(Box.createVerticalGlue()); configPane.add(question); configPane.add(audioCB); configPane.add(nicCB); configPane.add(tvCB); configPane.add(Box.createVerticalGlue()); JLabel audioPane = new JLabel("Audio stuff"); JLabel nicPane = new JLabel("Networking stuff"); JLabel tvPane = new JLabel("Video stuff"); JLabel helpPane = new JLabel("Help information"); audioCB.addItemListener(new TabManager(audioPane)); nicCB.addItemListener(new TabManager(nicPane)); tvCB.addItemListener(new TabManager(tvPane)); config.addTab("System", null, configPane, "Choose Installed Options"); config.addTab("Audio", null, audioPane, "Audio system configuration"); config.addTab("Networking", null, nicPane, "Networking configuration"); config.addTab("Video", null, tvPane, "Video system configuration"); config.addTab("Help", null, helpPane, "How Do I..."); getContentPane().add(config, BorderLayout.CENTER); }
From source file:MainClass.java
public MainClass() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/* w ww . j a v a2 s . co m*/ cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); undoButton.setEnabled(false); redoButton.setEnabled(false); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:UndoableToggleApp2.java
public UndoableToggleApp2() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from w ww.j a va 2 s .c o m cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.setEnabled(false); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); Box undoRedoEndBox = new Box(BoxLayout.X_AXIS); undoRedoEndBox.add(Box.createGlue()); undoRedoEndBox.add(undoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(redoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(endButton); undoRedoEndBox.add(Box.createGlue()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }
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)); }//from w w w .jav a 2 s . c o 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:UndoableToggleApp4.java
public UndoableToggleApp4() { SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from www . j a v a 2 s. co m cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); startButton.setEnabled(true); endButton.setEnabled(false); undoButton.setEnabled(false); redoButton.setEnabled(false); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit = new StateEdit(UndoableToggleApp4.this); startButton.setEnabled(false); endButton.setEnabled(true); // undoButton.setEnabled(edit.canUndo()); // // NOTE: We really don't want to be able to undo until end() is pressed, // but StateEdit does not enforce this for us! undoButton.setEnabled(false); redoButton.setEnabled(edit.canRedo()); } }); endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); startButton.setEnabled(true); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); // Add a listener to the undo button. It attempts to call undo() on the // current edit, then enables/disables the undo/redo buttons as appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Lay out the state/end and undo/redo buttons. Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(startButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(endButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); // Lay out the main frame. Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }