List of usage examples for java.awt BorderLayout WEST
String WEST
To view the source code for java.awt BorderLayout WEST.
Click Source Link
From source file:DndTree.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel top = new JPanel(new BorderLayout()); JLabel dragLabel = new JLabel("Drag me:"); JTextField text = new JTextField(); text.setDragEnabled(true);/*from ww w.jav a 2 s.c o m*/ top.add(dragLabel, BorderLayout.WEST); top.add(text, BorderLayout.CENTER); f.add(top, BorderLayout.NORTH); final JTree tree = new JTree(); final DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); tree.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor) || !support.isDrop()) { return false; } JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation(); return dropLocation.getPath() != null; } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation(); TreePath path = dropLocation.getPath(); Transferable transferable = support.getTransferable(); String transferData; try { transferData = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (IOException e) { return false; } catch (UnsupportedFlavorException e) { return false; } int childIndex = dropLocation.getChildIndex(); if (childIndex == -1) { childIndex = model.getChildCount(path.getLastPathComponent()); } DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(transferData); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); model.insertNodeInto(newNode, parentNode, childIndex); TreePath newPath = path.pathByAddingChild(newNode); tree.makeVisible(newPath); tree.scrollRectToVisible(tree.getPathBounds(newPath)); return true; } }); JScrollPane pane = new JScrollPane(tree); f.add(pane, BorderLayout.CENTER); tree.setDropMode(DropMode.INSERT); f.setSize(300, 400); f.setVisible(true); }
From source file:DndTree.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel top = new JPanel(new BorderLayout()); JLabel dragLabel = new JLabel("Drag me:"); JTextField text = new JTextField(); text.setDragEnabled(true);/* www. j av a 2 s .c o m*/ top.add(dragLabel, BorderLayout.WEST); top.add(text, BorderLayout.CENTER); f.add(top, BorderLayout.NORTH); final JTree tree = new JTree(); final DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); tree.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor) || !support.isDrop()) { return false; } JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation(); return dropLocation.getPath() != null; } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation(); TreePath path = dropLocation.getPath(); Transferable transferable = support.getTransferable(); String transferData; try { transferData = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (IOException e) { return false; } catch (UnsupportedFlavorException e) { return false; } int childIndex = dropLocation.getChildIndex(); if (childIndex == -1) { childIndex = model.getChildCount(path.getLastPathComponent()); } DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(transferData); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); model.insertNodeInto(newNode, parentNode, childIndex); TreePath newPath = path.pathByAddingChild(newNode); tree.makeVisible(newPath); tree.scrollRectToVisible(tree.getPathBounds(newPath)); return true; } }); JScrollPane pane = new JScrollPane(tree); f.add(pane, BorderLayout.CENTER); tree.setDropMode(DropMode.ON_OR_INSERT); f.setSize(300, 400); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Sorting JTable"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyTableModel model = new MyTableModel(); JTable table = new JTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/*from w w w .j a va 2 s .co m*/ JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter"); panel.add(label, BorderLayout.WEST); final JTextField filterText = new JTextField("Y"); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); JButton button = new JButton("Filter"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = filterText.getText(); try { sorter.setRowFilter(RowFilter.regexFilter(text)); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } }); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH); String days[] = symbols.getWeekdays(); SpinnerModel model1 = new SpinnerListModel(days); JSpinner spinner1 = new JSpinner(model1); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }//from www . ja v a 2 s .c o m }; spinner1.addChangeListener(listener); JLabel label1 = new JLabel("French Days/List"); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(label1, BorderLayout.WEST); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.NORTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:TickSliders.java
public static void main(String args[]) { JFrame f = new JFrame("Tick Slider"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // No Ticks//from ww w . j av a 2s . c o m JSlider jSliderOne = new JSlider(); // Major Tick 25 - Minor 5 JSlider jSliderTwo = new JSlider(); jSliderTwo.setMinorTickSpacing(5); jSliderTwo.setMajorTickSpacing(25); jSliderTwo.setPaintTicks(true); jSliderTwo.setSnapToTicks(true); // Major Tick 25 - Minor 6 JSlider jSliderThree = new JSlider(JSlider.VERTICAL); jSliderThree.setMinorTickSpacing(6); jSliderThree.setMajorTickSpacing(25); jSliderThree.setPaintTicks(true); JSlider jSliderFour = new JSlider(JSlider.VERTICAL); // Major Tick 25 - Minor 1 jSliderFour.setMinorTickSpacing(1); jSliderFour.setMajorTickSpacing(25); jSliderFour.setPaintTicks(true); Container c = f.getContentPane(); c.add(jSliderOne, BorderLayout.NORTH); c.add(jSliderTwo, BorderLayout.SOUTH); c.add(jSliderThree, BorderLayout.WEST); c.add(jSliderFour, BorderLayout.EAST); f.setSize(300, 200); f.setVisible(true); }
From source file:GroupRadio.java
public static void main(String args[]) { JFrame frame = new JFrame("Grouping Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container sliceContainer = RadioButtonUtils.createRadioButtonGrouping(sliceOptions, "Slice Count"); Container crustContainer = RadioButtonUtils.createRadioButtonGrouping(crustOptions, "Crust Type"); Container contentPane = frame.getContentPane(); contentPane.add(sliceContainer, BorderLayout.WEST); contentPane.add(crustContainer, BorderLayout.EAST); frame.setSize(300, 200);//from www . ja v a2 s. c o m frame.setVisible(true); }
From source file:BorderLayoutExample.java
public static void main(String[] args) { BorderSample bs = new BorderSample(); bs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = bs.getContentPane(); pane.setLayout(new BorderLayout()); JLabel label = new JLabel("North", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.NORTH); label = new JLabel("South", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.SOUTH); label = new JLabel("East", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.EAST); label = new JLabel("West", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.WEST); label = new JLabel("Center", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.CENTER); bs.setSize(400, 300);//from w w w . java 2 s . co m bs.setVisible(true); }
From source file:RadioButtonUtils.java
public static void main(String args[]) { JFrame frame = new JFrame("Grouping Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container sliceContainer = RadioButtonUtils.createRadioButtonGrouping(sliceOptions, "Slice Count"); Container crustContainer = RadioButtonUtils.createRadioButtonGrouping(crustOptions, "Crust Type"); frame.add(sliceContainer, BorderLayout.WEST); frame.add(crustContainer, BorderLayout.EAST); frame.setSize(300, 200);//from w w w . ja v a2 s . co m frame.setVisible(true); }
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()); }/* w w w.ja v a 2 s. c om*/ }; 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:MovingIconTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JButton b;/*w w w .ja v a 2s . c om*/ Icon icon = new PieIcon(Color.red); b = new JButton("Default", icon); contentPane.add(b, BorderLayout.NORTH); b = new JButton("Text Left", icon); b.setHorizontalTextPosition(JButton.LEFT); contentPane.add(b, BorderLayout.SOUTH); b = new JButton("Text Up", icon); b.setHorizontalTextPosition(JButton.CENTER); b.setVerticalTextPosition(JButton.TOP); contentPane.add(b, BorderLayout.EAST); b = new JButton("Text Down", icon); b.setHorizontalTextPosition(JButton.CENTER); b.setVerticalTextPosition(JButton.BOTTOM); contentPane.add(b, BorderLayout.WEST); b = new JButton("Align Bottom Left", icon); b.setHorizontalAlignment(JButton.LEFT); b.setVerticalAlignment(JButton.BOTTOM); contentPane.add(b, BorderLayout.CENTER); frame.setSize(300, 200); frame.show(); }