List of usage examples for javax.swing Box createHorizontalStrut
public static Component createHorizontalStrut(int width)
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);// ww w . j ava 2s . 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); 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:Main.java
public Main() { super(new BorderLayout()); listModel.addElement("A"); listModel.addElement("B"); listModel.addElement("C"); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);//from w ww . ja va 2 s . c o m list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(addCommand); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(addCommand); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(deleteCommand); fireButton.setActionCommand(deleteCommand); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); System.out.println(name); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:Main.java
public Main() { super(new BorderLayout()); listModel = new DefaultListModel(); listModel.addElement("Debbie Scott"); listModel.addElement("Scott Hommel"); listModel.addElement("Sharon Zakhour"); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*w w w . j a v a 2s. co m*/ list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
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);//ww w . ja v a 2s . c om 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:PizzaGridBagLayout.java
public PizzaGridBagLayout() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel1 = new JPanel(); panel1.setLayout(new GridBagLayout()); addItem(panel1, new JLabel("Name:"), 0, 0, 1, 1, GridBagConstraints.EAST); addItem(panel1, new JLabel("Phone:"), 0, 1, 1, 1, GridBagConstraints.EAST); addItem(panel1, new JLabel("Address:"), 0, 2, 1, 1, GridBagConstraints.EAST); addItem(panel1, name, 1, 0, 2, 1, GridBagConstraints.WEST); addItem(panel1, phone, 1, 1, 1, 1, GridBagConstraints.WEST); addItem(panel1, address, 1, 2, 2, 1, GridBagConstraints.WEST); Box sizeBox = Box.createVerticalBox(); ButtonGroup sizeGroup = new ButtonGroup(); sizeGroup.add(small);//from w ww . j ava 2s . c om sizeGroup.add(medium); sizeGroup.add(large); sizeBox.add(small); sizeBox.add(medium); sizeBox.add(large); sizeBox.setBorder(BorderFactory.createTitledBorder("Size")); addItem(panel1, sizeBox, 0, 3, 1, 1, GridBagConstraints.NORTH); Box styleBox = Box.createVerticalBox(); ButtonGroup styleGroup = new ButtonGroup(); styleGroup.add(thin); styleGroup.add(thick); styleBox.add(thin); styleBox.add(thick); styleBox.setBorder(BorderFactory. createTitledBorder("Style")); addItem(panel1, styleBox, 1, 3, 1, 1, GridBagConstraints.NORTH); Box topBox = Box.createVerticalBox(); ButtonGroup topGroup = new ButtonGroup(); topGroup.add(pepperoni); topGroup.add(mushrooms); topGroup.add(anchovies); topBox.add(pepperoni); topBox.add(mushrooms); topBox.add(anchovies); topBox.setBorder(BorderFactory.createTitledBorder("Toppings")); addItem(panel1, topBox, 2, 3, 1, 1, GridBagConstraints.NORTH); Box buttonBox = Box.createHorizontalBox(); buttonBox.add(okButton); buttonBox.add(Box.createHorizontalStrut(20)); buttonBox.add(closeButton); addItem(panel1, buttonBox, 2, 4, 1, 1, GridBagConstraints.NORTH); this.add(panel1); this.pack(); this.setVisible(true); }
From source file:com.limegroup.gnutella.gui.init.LanguagePanel.java
/** * Constructs a LanguagePanel that will notify the given listener when the * language changes.//from w ww . ja v a2 s . c o m */ public LanguagePanel(ActionListener actionListener) { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.actionListener = actionListener; this.languageLabel = new JLabel(); languageOptions = new JComboBox<Object>(); Font font = new Font("Dialog", Font.PLAIN, 11); languageOptions.setFont(font); Locale[] locales = LanguageUtils.getLocales(font); languageOptions.setModel(new DefaultComboBoxModel<Object>(locales)); languageOptions.setRenderer(LanguageFlagFactory.getListRenderer()); Locale locale = guessLocale(locales); languageOptions.setSelectedItem(locale); applySettings(false); // It is important that the listener is added after the selected item // is set. Otherwise the listener will call methods that are not ready // to be called at this point. languageOptions.addItemListener(new StateListener()); add(languageLabel); add(Box.createHorizontalStrut(5)); add(languageOptions); }
From source file:UndoableToggleApp3.java
public UndoableToggleApp3() { // Create some toggle buttons. UndoableJToggleButton tog1 = new UndoableJToggleButton("One"); UndoableJToggleButton tog2 = new UndoableJToggleButton("Two"); UndoableJToggleButton tog3 = new UndoableJToggleButton("Three"); // Add our listener to each toggle button. SimpleUEListener sl = new SimpleUEListener(); tog1.addUndoableEditListener(sl);/*from w w w . j a v a2 s.co m*/ tog2.addUndoableEditListener(sl); tog3.addUndoableEditListener(sl); // Lay out the buttons. Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog1); buttonBox.add(tog2); buttonBox.add(tog3); // Create undo and redo buttons (initially disabled). undoButton = new JButton("Undo"); redoButton = new JButton("Redo"); undoButton.setEnabled(false); redoButton.setEnabled(false); // Add a listener to the undo button. It attempts to call undo() on the // UndoManager, then enables/disables the undo/redo buttons as // appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { manager.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { updateButtons(); } } }); // Add a redo listener: just like the undo listener. redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { manager.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { updateButtons(); } } }); // Lay out the undo/redo buttons. 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()); // Lay out the main frame. getContentPane().setLayout(new BorderLayout()); getContentPane().add(buttonBox, BorderLayout.CENTER); getContentPane().add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:brainflow.app.presentation.controls.FileObjectGroupSelector.java
public FileObjectGroupSelector(FileObject root) throws FileSystemException { if (root.getType() != FileType.FOLDER) { throw new IllegalArgumentException("root file must be a directory"); }/*w ww. j a v a2s. c o m*/ rootFolder = root; explorer = new FileExplorer(rootFolder); explorer.getJTree().setRootVisible(false); explorer.getJTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); setLayout(new BorderLayout()); Box topPanel = new Box(BoxLayout.X_AXIS); topPanel.setBorder(BorderFactory.createEmptyBorder(8, 12, 8, 8)); topPanel.add(regexLabel); topPanel.add(regexField); topPanel.add(Box.createHorizontalStrut(4)); topPanel.add(searchType); add(topPanel, BorderLayout.NORTH); //JPanel mainPanel = new JPanel(); //MigLayout layout = new MigLayout(""); // mainPanel.setLayout(layout); //add(regexLabel); //add(regexField, "gap left 0, growx"); //add(findButton, "align right, wrap"); //add(searchType, "wrap"); //add(createSplitPane(), "span 3, grow, wrap"); add(createSplitPane(), BorderLayout.CENTER); depthSpinner.setMaximumSize(new Dimension(50, 200)); depthSpinner.setModel(new SpinnerNumberModel(recursiveDepth, 0, 5, 1)); JPanel bottomPanel = new JPanel(); MigLayout layout = new MigLayout("", "[][grow]", "[][]"); bottomPanel.setLayout(layout); //bottomPanel.setBorder(BorderFactory.createEmptyBorder(4,12,8,8)); bottomPanel.add(new JLabel("Root Folder: ")); rootField.setEditable(false); rootField.setText(root.getName().getBaseName()); bottomPanel.add(rootField, "wrap, width 150:150:150"); bottomPanel.add(new JLabel("Search Depth: "), "gap top 8"); bottomPanel.add(depthSpinner, "width 35:45:55, wrap"); add(bottomPanel, BorderLayout.SOUTH); explorer.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getPath(); Object[] obj = path.getPath(); Object lastNode = obj[obj.length - 1]; if (lastNode instanceof FileExplorer.FileObjectNode) { FileExplorer.FileObjectNode fnode = (FileExplorer.FileObjectNode) lastNode; try { if (fnode.getFileObject().getType() == FileType.FOLDER) { rootField.setText(fnode.getFileObject().getName().getBaseName()); rootFolder = fnode.getFileObject(); updateFileList(); } } catch (FileSystemException ex) { throw new RuntimeException(ex); } } } }); depthSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { recursiveDepth = ((Number) depthSpinner.getValue()).intValue(); updateFileList(); } }); regexField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateFileList(); System.out.println(Arrays.toString(explorer.getSelectedNodes().toArray())); } }); }
From source file:UndoableToggleApp.java
public UndoableToggleApp() { // Create some toggle buttons (and subclasses) JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); // Add our listener to each toggle button SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/*from w ww . java 2 s . c o m*/ cb.addActionListener(sl); radio.addActionListener(sl); // Layout the buttons Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); // Create undo and redo buttons (initially disabled) undoButton = new JButton("Undo"); redoButton = new JButton("Redo"); undoButton.setEnabled(false); redoButton.setEnabled(false); // 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()); } } }); // Add a redo listener: just like the undo listener, but for redo this // time. 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()); } } }); // Layout the undo/redo buttons 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()); // Layout the main frame Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:com.diversityarrays.wizard.WizardRunner.java
protected void handleWizardEnded(WizardEndedReason reason) { if (handler != null) { handler.execute(reason);//from w ww. j a v a 2s. c o m } status.setText(reason.toString()); WizardRunner.this.setEnabled(false); RootPaneContainer rpc = ((RootPaneContainer) window); rpc.getContentPane().remove(this); Container cp = rpc.getContentPane(); cp.removeAll(); JLabel label = new JLabel(reason.toString()); Box n = Box.createHorizontalBox(); n.add(Box.createHorizontalGlue()); n.add(label); n.add(Box.createHorizontalGlue()); cp.add(n, BorderLayout.CENTER); Box box = Box.createHorizontalBox(); box.add(Box.createHorizontalGlue()); box.add(new JButton(closeMe)); box.add(Box.createHorizontalStrut(20)); cp.add(box, BorderLayout.SOUTH); cp.setBackground(Color.LIGHT_GRAY); Dimension d = window.getSize(); ++d.width; window.setSize(d); }