List of usage examples for java.awt BorderLayout SOUTH
String SOUTH
To view the source code for java.awt BorderLayout SOUTH.
Click Source Link
From source file:FocusTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); FocusListener listener = new FocusListener() { public void focusGained(FocusEvent e) { dumpInfo(e);/*w w w .j a va2 s .co m*/ } public void focusLost(FocusEvent e) { dumpInfo(e); } private void dumpInfo(FocusEvent e) { System.out.println("Source : " + name(e.getComponent())); System.out.println("Opposite : " + name(e.getOppositeComponent())); System.out.println("Temporary: " + e.isTemporary()); } private String name(Component c) { return (c == null) ? null : c.getName(); } }; // First JPanel panel = new JPanel(); JLabel label = new JLabel("Label 1: "); JTextField text = new JTextField("Type your text", 15); text.setName("First"); text.addFocusListener(listener); label.setDisplayedMnemonic(KeyEvent.VK_1); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.NORTH); // Second panel = new JPanel(); label = new JLabel("Label 2: "); text = new JTextField("14.0", 10); text.setName("Second"); text.addFocusListener(listener); text.setHorizontalAlignment(JTextField.RIGHT); label.setDisplayedMnemonic(KeyEvent.VK_2); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.SOUTH); frame.pack(); frame.show(); }
From source file:JTextFieldSample.java
public static void main(String args[]) { String title = (args.length == 0 ? "TextField Listener Example" : args[0]); JFrame frame = new JFrame(title); Container content = frame.getContentPane(); JPanel namePanel = new JPanel(new BorderLayout()); JLabel nameLabel = new JLabel("Name: "); nameLabel.setDisplayedMnemonic(KeyEvent.VK_N); JTextField nameTextField = new JTextField(); nameLabel.setLabelFor(nameTextField); namePanel.add(nameLabel, BorderLayout.WEST); namePanel.add(nameTextField, BorderLayout.CENTER); content.add(namePanel, BorderLayout.NORTH); JPanel cityPanel = new JPanel(new BorderLayout()); JLabel cityLabel = new JLabel("City: "); cityLabel.setDisplayedMnemonic(KeyEvent.VK_C); JTextField cityTextField = new JTextField(); cityLabel.setLabelFor(cityTextField); cityPanel.add(cityLabel, BorderLayout.WEST); cityPanel.add(cityTextField, BorderLayout.CENTER); content.add(cityPanel, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Command: " + actionEvent.getActionCommand()); }//from w w w .ja va 2 s . com }; nameTextField.setActionCommand("Yo"); nameTextField.addActionListener(actionListener); cityTextField.addActionListener(actionListener); KeyListener keyListener = new KeyListener() { public void keyPressed(KeyEvent keyEvent) { printIt("Pressed", keyEvent); } public void keyReleased(KeyEvent keyEvent) { printIt("Released", keyEvent); } public void keyTyped(KeyEvent keyEvent) { printIt("Typed", keyEvent); } private void printIt(String title, KeyEvent keyEvent) { int keyCode = keyEvent.getKeyCode(); String keyText = KeyEvent.getKeyText(keyCode); System.out.println(title + " : " + keyText + " / " + keyEvent.getKeyChar()); } }; nameTextField.addKeyListener(keyListener); cityTextField.addKeyListener(keyListener); InputVerifier verifier = new InputVerifier() { public boolean verify(JComponent input) { final JTextComponent source = (JTextComponent) input; String text = source.getText(); if ((text.length() != 0) && !(text.equals("Exit"))) { Runnable runnable = new Runnable() { public void run() { JOptionPane.showMessageDialog(source, "Can't leave.", "Error Dialog", JOptionPane.ERROR_MESSAGE); } }; SwingUtilities.invokeLater(runnable); return false; } else { return true; } } }; nameTextField.setInputVerifier(verifier); cityTextField.setInputVerifier(verifier); DocumentListener documentListener = new DocumentListener() { public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); String typeString = null; if (type.equals(DocumentEvent.EventType.CHANGE)) { typeString = "Change"; } else if (type.equals(DocumentEvent.EventType.INSERT)) { typeString = "Insert"; } else if (type.equals(DocumentEvent.EventType.REMOVE)) { typeString = "Remove"; } System.out.print("Type : " + typeString + " / "); Document source = documentEvent.getDocument(); int length = source.getLength(); try { System.out.println("Contents: " + source.getText(0, length)); } catch (BadLocationException badLocationException) { System.out.println("Contents: Unknown"); } } }; nameTextField.getDocument().addDocumentListener(documentListener); cityTextField.getDocument().addDocumentListener(documentListener); frame.setSize(250, 150); frame.setVisible(true); }
From source file:SampleSliders.java
public static void main(String args[]) { String title = (args.length == 0 ? "Sample Slider" : args[0]); JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider js1 = new JSlider(); js1.putClientProperty("JSlider.isFilled", Boolean.TRUE); JSlider js2 = new JSlider(); js2.setMajorTickSpacing(25);/* www . j a v a2s . c om*/ js2.setPaintTicks(true); js2.setSnapToTicks(true); JSlider js3 = new JSlider(JSlider.VERTICAL); js3.setPaintTrack(false); js3.setMinorTickSpacing(5); js3.setMajorTickSpacing(10); js3.setPaintTicks(true); js3.setPaintLabels(true); js3.setSnapToTicks(true); JSlider js4 = new JSlider(JSlider.VERTICAL); Hashtable table = new Hashtable(); table.put(new Integer(0), new JLabel(new DiamondIcon(Color.red))); table.put(new Integer(10), new JLabel("Ten")); table.put(new Integer(25), new JLabel("Twenty-Five")); table.put(new Integer(34), new JLabel("Thirty-Four")); table.put(new Integer(52), new JLabel("Fifty-Two")); table.put(new Integer(70), new JLabel("Seventy")); table.put(new Integer(82), new JLabel("Eighty-Two")); table.put(new Integer(100), new JLabel(new DiamondIcon(Color.black))); js4.setLabelTable(table); js4.setPaintLabels(true); js4.setSnapToTicks(true); Container c = f.getContentPane(); c.add(js1, BorderLayout.NORTH); c.add(js2, BorderLayout.SOUTH); c.add(js3, BorderLayout.WEST); c.add(js4, BorderLayout.EAST); f.setSize(300, 200); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Action Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Action printAction = new PrintHelloAction(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu);// w w w . j av a 2 s . c om menu.add(new JMenuItem(printAction)); JToolBar toolbar = new JToolBar(); toolbar.add(new JButton(printAction)); JButton enableButton = new JButton("Enable"); ActionListener enableActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.setEnabled(true); } }; enableButton.addActionListener(enableActionListener); JButton disableButton = new JButton("Disable"); ActionListener disableActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.setEnabled(false); } }; disableButton.addActionListener(disableActionListener); JButton relabelButton = new JButton("Relabel"); ActionListener relabelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.putValue(Action.NAME, "Hello, World"); } }; relabelButton.addActionListener(relabelActionListener); JPanel buttonPanel = new JPanel(); buttonPanel.add(enableButton); buttonPanel.add(disableButton); buttonPanel.add(relabelButton); frame.setJMenuBar(menuBar); frame.add(toolbar, BorderLayout.SOUTH); frame.add(buttonPanel, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyTreeNode root = new MyTreeNode(1, 0); DefaultTreeModel model = new DefaultTreeModel(root); JProgressBar bar = new JProgressBar(); PropertyChangeListener progressListener = new PropertyChangeListener() { @Override/* w w w . j a v a 2 s.co m*/ public void propertyChange(PropertyChangeEvent evt) { bar.setValue((Integer) evt.getNewValue()); } }; JTree tree = new JTree(); tree.setShowsRootHandles(true); tree.addTreeWillExpandListener(new TreeWillExpandListener() { @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { TreePath path = event.getPath(); if (path.getLastPathComponent() instanceof MyTreeNode) { MyTreeNode node = (MyTreeNode) path.getLastPathComponent(); node.loadChildren(model, progressListener); } } @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { } }); tree.setModel(model); root.loadChildren(model, progressListener); frame.add(new JScrollPane(tree)); frame.add(bar, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:LoadSave.java
public static void main(String args[]) { final String filename = "text.out"; JFrame frame = new JFrame("Loading/Saving Example"); Container content = frame.getContentPane(); final JTextField textField = new JTextField(); content.add(textField, BorderLayout.NORTH); JPanel panel = new JPanel(); Action loadAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { doLoadCommand(textField, filename); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace();//from w w w . j a v a2 s . c om } } }; loadAction.putValue(Action.NAME, "Load"); JButton loadButton = new JButton(loadAction); panel.add(loadButton); Action saveAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { doSaveCommand(textField, filename); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }; saveAction.putValue(Action.NAME, "Save"); JButton saveButton = new JButton(saveAction); panel.add(saveButton); Action clearAction = new AbstractAction() { { putValue(Action.NAME, "Clear"); } public void actionPerformed(ActionEvent e) { textField.setText(""); } }; JButton clearButton = new JButton(clearAction); panel.add(clearButton); content.add(panel, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:PropertyChangeListenerDemo.java
public static void main(String args[]) { Runnable runner = new Runnable() { public void run() { JFrame frame = new JFrame("Button Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button1 = new JButton("Select Me"); final JButton button2 = new JButton("No Select Me"); final Random random = new Random(); // Define ActionListener ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JButton button = (JButton) actionEvent.getSource(); int red = random.nextInt(255); int green = random.nextInt(255); int blue = random.nextInt(255); button.setBackground(new Color(red, green, blue)); }/* w w w . j a v a 2 s. c om*/ }; // Define PropertyChangeListener PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { String property = propertyChangeEvent.getPropertyName(); if ("background".equals(property)) { button2.setBackground((Color) propertyChangeEvent.getNewValue()); } } }; button1.addActionListener(actionListener); button1.addPropertyChangeListener(propertyChangeListener); button2.addActionListener(actionListener); frame.add(button1, BorderLayout.NORTH); frame.add(button2, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); } }; EventQueue.invokeLater(runner); }
From source file:KeyTextComponent.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new KeyTextComponent(), BorderLayout.CENTER); JTextField field = new JTextField(); field.setText("Click above blank area to request focus"); frame.add(field, BorderLayout.SOUTH); frame.setSize(300, 100);/* w w w. ja v a2 s.co m*/ frame.setVisible(true); field.requestFocus(); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); CheckBoxNode accessibilityOptions[] = { new CheckBoxNode("A", false), new CheckBoxNode("B", true) }; CheckBoxNode browsingOptions[] = { new CheckBoxNode("C", true), new CheckBoxNode("D", true), new CheckBoxNode("E", true), new CheckBoxNode("F", false) }; Vector accessVector = new NamedVector("G", accessibilityOptions); Vector browseVector = new NamedVector("H", browsingOptions); Object rootNodes[] = { accessVector, browseVector }; Vector rootVector = new NamedVector("Root", rootNodes); tree = new JTree(rootVector); CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer(); tree.setCellRenderer(renderer);//from www . ja v a 2s . co m tree.setCellEditor(new CheckBoxNodeEditor(tree)); tree.setEditable(true); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(); JButton button = new JButton("new node"); buttonPanel.add(button); frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH); button.addActionListener(e -> { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New node"); root.add(newNode); model.reload(); }); frame.setSize(300, 450); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Select Me"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("I was selected."); }// w w w . j av a 2 s. c o m }; MouseListener mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { int modifiers = mouseEvent.getModifiers(); if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { System.out.println("Left button pressed."); } if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) { System.out.println("Middle button pressed."); } if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { System.out.println("Right button pressed."); } } public void mouseReleased(MouseEvent mouseEvent) { if (SwingUtilities.isLeftMouseButton(mouseEvent)) { System.out.println("Left button released."); } if (SwingUtilities.isMiddleMouseButton(mouseEvent)) { System.out.println("Middle button released."); } if (SwingUtilities.isRightMouseButton(mouseEvent)) { System.out.println("Right button released."); } System.out.println(); } }; button.addActionListener(actionListener); button.addMouseListener(mouseListener); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }