List of usage examples for java.awt BorderLayout NORTH
String NORTH
To view the source code for java.awt BorderLayout NORTH.
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 w w w .ja va2 s .c om 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("Verifier Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField1 = new JTextField(); JTextField textField2 = new JTextField(); JTextField textField3 = new JTextField(); InputVerifier verifier = new InputVerifier() { public boolean verify(JComponent comp) { boolean returnValue; JTextField textField = (JTextField) comp; try { Integer.parseInt(textField.getText()); returnValue = true;//from w w w . j a v a 2s.co m } catch (NumberFormatException e) { returnValue = false; } return returnValue; } }; textField1.setInputVerifier(verifier); textField3.setInputVerifier(verifier); Container contentPane = frame.getContentPane(); contentPane.add(textField1, BorderLayout.NORTH); contentPane.add(textField2, BorderLayout.CENTER); contentPane.add(textField3, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:MultiKeyCombo.java
public static void main(String args[]) { String labels[] = { "One", "Only", "Once", "Okay", "oneself", "onlooker", "Onslaught", "Onyx", "onus", "onward" }; JFrame f = new JFrame("Example JList"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox jc = new JComboBox(labels); MultiKeySelectionManager mk = new MultiKeySelectionManager(); jc.setKeySelectionManager(mk);/* w ww . j a v a 2 s . c om*/ // jc.setKeySelectionManager (new JComboBox.KeySelectionManager() { // public int selectionForKey (char aKey, ComboBoxModel aModel) { // return -1; // } // }); Container c = f.getContentPane(); c.add(jc, BorderLayout.NORTH); f.setSize(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton loadButton = new JButton("Display Image"); loadButton.addActionListener(ev -> { JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.addChoosableFileFilter(/*from w ww. j av a 2 s . c o m*/ new FileNameExtensionFilter("Image files", new String[] { "png", "jpg", "jpeg", "gif" })); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { Image image = ImageIO.read(fc.getSelectedFile()); if (image != null) { JPanel panel = new JPanel(new BorderLayout(10, 10)); panel.add(new JLabel(fc.getSelectedFile().toString()), BorderLayout.NORTH); panel.add(new JLabel(new ImageIcon(image))); JOptionPane.showMessageDialog(frame, panel); } } catch (Exception ex) { ex.printStackTrace(); } } }); frame.add(loadButton); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel userPanel = new JPanel(new BorderLayout()); JLabel userLabel = new JLabel("Username: "); userLabel.setDisplayedMnemonic(KeyEvent.VK_U); JTextField userTextField = new JTextField(); userLabel.setLabelFor(userTextField); userPanel.add(userLabel, BorderLayout.WEST); userPanel.add(userTextField, BorderLayout.CENTER); JPanel passPanel = new JPanel(new BorderLayout()); JLabel passLabel = new JLabel("Password: "); passLabel.setDisplayedMnemonic('p'); JPasswordField passTextField = new JPasswordField(); passLabel.setLabelFor(passTextField); passPanel.add(passLabel, BorderLayout.WEST); passPanel.add(passTextField, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); panel.add(userPanel, BorderLayout.NORTH); panel.add(passPanel, BorderLayout.SOUTH); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150);//w ww . j a va 2 s . co m frame.setVisible(true); }
From source file:FileSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JFileChooser Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); final JLabel directoryLabel = new JLabel(); contentPane.add(directoryLabel, BorderLayout.NORTH); final JLabel filenameLabel = new JLabel(); contentPane.add(filenameLabel, BorderLayout.SOUTH); final JButton button = new JButton("Open FileChooser"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component parent = (Component) actionEvent.getSource(); JFileChooser fileChooser = new JFileChooser("."); fileChooser.setAccessory(new LabelAccessory(fileChooser)); FileView view = new JavaFileView(); fileChooser.setFileView(view); int status = fileChooser.showOpenDialog(parent); if (status == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); directoryLabel.setText(selectedFile.getParent()); filenameLabel.setText(selectedFile.getName()); } else if (status == JFileChooser.CANCEL_OPTION) { directoryLabel.setText(" "); filenameLabel.setText(" "); }/*w ww . j a v a 2 s . co m*/ } }; button.addActionListener(actionListener); contentPane.add(button, BorderLayout.CENTER); frame.setSize(300, 200); 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 w w w .ja v a 2s . co 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:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Selecting CheckBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox checkBox = new JCheckBox("A"); // Define ChangeListener ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { AbstractButton abstractButton = (AbstractButton) changeEvent.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean armed = buttonModel.isArmed(); boolean pressed = buttonModel.isPressed(); boolean selected = buttonModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); }/*from w w w .j a v a 2 s . c o m*/ }; // Attach Listeners checkBox.addChangeListener(changeListener); checkBox.setMnemonic(KeyEvent.VK_S); frame.add(checkBox, BorderLayout.NORTH); frame.setSize(300, 100); 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 w ww .j a v a 2 s . co 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:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Password Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel userPanel = new JPanel(new BorderLayout()); JLabel userLabel = new JLabel("Username: "); userLabel.setDisplayedMnemonic(KeyEvent.VK_U); JTextField userTextField = new JTextField(); userLabel.setLabelFor(userTextField); userPanel.add(userLabel, BorderLayout.WEST); userPanel.add(userTextField, BorderLayout.CENTER); JPanel passPanel = new JPanel(new BorderLayout()); JLabel passLabel = new JLabel("Password: "); passLabel.setDisplayedMnemonic(KeyEvent.VK_P); JPasswordField passTextField = new JPasswordField(); passLabel.setLabelFor(passTextField); passPanel.add(passLabel, BorderLayout.WEST); passPanel.add(passTextField, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); panel.add(userPanel, BorderLayout.NORTH); panel.add(passPanel, BorderLayout.SOUTH); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150);//from www . j a va 2 s .co m frame.setVisible(true); }