List of usage examples for javax.swing Box createGlue
public static Component createGlue()
From source file:be.tutul.naheulcraft.launcher.auth.LogInForm.java
private void createInterface() { setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = 2;/*from w w w .j a va 2s. c o m*/ constraints.gridx = 0; constraints.gridy = -1; constraints.weightx = 1.0D; add(Box.createGlue()); JLabel usernameLabel = new JLabel("Pseudo : "); Font labelFont = usernameLabel.getFont().deriveFont(1); Font smalltextFont = usernameLabel.getFont().deriveFont(labelFont.getSize() - 2.0F); usernameLabel.setFont(labelFont); add(usernameLabel, constraints); add(this.usernameField, constraints); add(Box.createVerticalStrut(10), constraints); JLabel passwordLabel = new JLabel("Mot de passe :"); passwordLabel.setFont(labelFont); add(passwordLabel, constraints); add(this.passwordField, constraints); JLabel forgotPasswordLabel = new JLabel("(oubli ?)"); forgotPasswordLabel.setCursor(new Cursor(12)); forgotPasswordLabel.setFont(smalltextFont); forgotPasswordLabel.setHorizontalAlignment(4); forgotPasswordLabel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { Util.openLink(Variables.lost); } catch (Exception e1) { LogInForm.this.login.getLauncher().getLogger() .error("Impossible d'ouvrir le lien pour les logins oublis"); JOptionPane.showMessageDialog(LogInForm.this.login.getLauncher().getPanel(), "Impossible d'ouvrir la page\nRendez-vous sur le site de NaheulCraft pour rcuprer vos identifiants", "Impossible d'ouvrir l'URL", 0); } } }); add(forgotPasswordLabel, constraints); createUserDropdownPanel(labelFont); add(this.userDropdownPanel, constraints); add(Box.createVerticalStrut(10), constraints); }
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);/*from w ww . j a v a2 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); 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:BoxLayoutTest.java
public Box createBox(boolean horizontal, boolean strutsAndGlue) { Box b;//from w w w.j a va 2 s .c om if (horizontal) b = Box.createHorizontalBox(); else b = Box.createVerticalBox(); b.add(new JLabel("Name: ")); b.add(new JTextField()); if (strutsAndGlue) if (horizontal) b.add(Box.createHorizontalStrut(5)); else b.add(Box.createVerticalStrut(5)); b.add(new JLabel("Password: ")); b.add(new JTextField()); if (strutsAndGlue) b.add(Box.createGlue()); b.add(new JButton("Ok")); return b; }
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);// w ww . ja v a 2 s . com 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: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 ava 2 s . com*/ 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: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);/* ww w . j a v a 2 s.com*/ 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:FieldValidator.java
private static JComponent createContent() { Dimension labelSize = new Dimension(80, 20); Box box = Box.createVerticalBox(); // A single LayerUI for all the fields. LayerUI<JFormattedTextField> layerUI = new ValidationLayerUI(); // Number field. JLabel numberLabel = new JLabel("Number:"); numberLabel.setHorizontalAlignment(SwingConstants.RIGHT); numberLabel.setPreferredSize(labelSize); NumberFormat numberFormat = NumberFormat.getInstance(); JFormattedTextField numberField = new JFormattedTextField(numberFormat); numberField.setColumns(16);//from w w w . ja v a 2s.c o m numberField.setFocusLostBehavior(JFormattedTextField.PERSIST); numberField.setValue(42); JPanel numberPanel = new JPanel(); numberPanel.add(numberLabel); numberPanel.add(new JLayer<JFormattedTextField>(numberField, layerUI)); // Date field. JLabel dateLabel = new JLabel("Date:"); dateLabel.setHorizontalAlignment(SwingConstants.RIGHT); dateLabel.setPreferredSize(labelSize); DateFormat dateFormat = DateFormat.getDateInstance(); JFormattedTextField dateField = new JFormattedTextField(dateFormat); dateField.setColumns(16); dateField.setFocusLostBehavior(JFormattedTextField.PERSIST); dateField.setValue(new java.util.Date()); JPanel datePanel = new JPanel(); datePanel.add(dateLabel); datePanel.add(new JLayer<JFormattedTextField>(dateField, layerUI)); // Time field. JLabel timeLabel = new JLabel("Time:"); timeLabel.setHorizontalAlignment(SwingConstants.RIGHT); timeLabel.setPreferredSize(labelSize); DateFormat timeFormat = DateFormat.getTimeInstance(); JFormattedTextField timeField = new JFormattedTextField(timeFormat); timeField.setColumns(16); timeField.setFocusLostBehavior(JFormattedTextField.PERSIST); timeField.setValue(new java.util.Date()); JPanel timePanel = new JPanel(); timePanel.add(timeLabel); timePanel.add(new JLayer<JFormattedTextField>(timeField, layerUI)); // Put them all in the box. box.add(Box.createGlue()); box.add(numberPanel); box.add(Box.createGlue()); box.add(datePanel); box.add(Box.createGlue()); box.add(timePanel); return box; }
From source file:Transfer.java
public Transfer() { // Establish the GUI Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);/*from w w w .ja va 2 s.c om*/ 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); // Add Listeners and Converters setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); // Mousing in the Label starts a Drag. 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); // Selecting in the ComboBox makes that the property that is xfered. propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); // Typing a word and pressing enter in the TextField tries // to set that as the font name. 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); } }); // Setting the Slider sets that font into the textfield. 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:UndoableToggleApp4.java
public UndoableToggleApp4() { SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/* w w w.j a va 2s .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); }
From source file:UndoableToggleApp2.java
public UndoableToggleApp2() { // Create some toggle buttons (and subclasses) JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); // Add our listener to each toggle button SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/*w w w .jav a2 s .c o m*/ cb.addActionListener(sl); radio.addActionListener(sl); // Lay out 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"); endButton = new JButton("End"); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.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()); } } }); // Add an end listener. This listener will call end() on the // CompoundEdit // and update the undo/redo buttons. endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); // Layout the undo/redo/end buttons 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()); // Layout the main frame Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }