List of usage examples for java.awt BorderLayout CENTER
String CENTER
To view the source code for java.awt BorderLayout CENTER.
Click Source Link
From source file:OptionPaneSample.java
public static void main(String args[]) { JFrame f = new JFrame("JOptionPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); Object response = JOptionPane.showInputDialog(source, "Where do you want to go tomorrow?", "JOptionPane Sample", JOptionPane.QUESTION_MESSAGE, null, new String[] { "A", "B", "C", "D", "E" }, "E"); System.out.println("Response: " + response); }/*w w w . j a va 2s . c om*/ }; button.addActionListener(actionListener); content.add(button, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> rowOne = new Vector<String>(); rowOne.addElement("Row1-Column1"); rowOne.addElement("Row1-Column2"); rowOne.addElement("Row1-Column3"); Vector<String> rowTwo = new Vector<String>(); rowTwo.addElement("Row2-Column1"); rowTwo.addElement("Row2-Column2"); rowTwo.addElement("Row2-Column3"); Vector<Vector> rowData = new Vector<Vector>(); rowData.addElement(rowOne);/* ww w. ja v a 2 s. c o m*/ rowData.addElement(rowTwo); Vector<String> columnNames = new Vector<String>(); columnNames.addElement("Column One"); columnNames.addElement("Column Two"); columnNames.addElement("Column Three"); JTable table = new JTable(rowData, columnNames); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:DesktopInternalFrameStyleSample.java
public static void main(final String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDesktopPane desktop = new JDesktopPane(); JInternalFrame internalFrames[] = { new JInternalFrame("Can Do All", true, true, true, true), new JInternalFrame("Not Resizable", false, true, true, true), new JInternalFrame("Not Closable", true, false, true, true), new JInternalFrame("Not Maximizable", true, true, false, true), new JInternalFrame("Not Iconifiable", true, true, true, false) }; int pos = 0;/*from w w w. ja v a 2 s . co m*/ for (JInternalFrame internalFrame : internalFrames) { desktop.add(internalFrame); internalFrame.setBounds(pos * 25, pos * 25, 200, 100); pos++; JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER); internalFrame.add(label, BorderLayout.CENTER); internalFrame.setVisible(true); } frame.add(desktop, BorderLayout.CENTER); frame.setSize(500, 300); frame.setVisible(true); }
From source file:TreeNodeVector.java
public static void main(final String args[]) { JFrame frame = new JFrame("JTreeSample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus", "Mars" }); Vector<Object> v2 = new TreeNodeVector<Object>("Three"); v2.add(System.getProperties()); v2.add(v1);// w ww . ja v a 2s .c o m Object rootNodes[] = { v1, v2 }; Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes); JTree tree = new JTree(rootVector); frame.add(new JScrollPane(tree), BorderLayout.CENTER); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox<String> comboBox = new JComboBox<>(new String[] { "A", "B", "C" }); comboBox.setEditable(true);/*from w w w . ja v a 2s. c o m*/ JTextField editorComponent = (JTextField) comboBox.getEditor().getEditorComponent(); editorComponent.addActionListener(e -> { editorComponent.transferFocus(); }); JPanel panel = new JPanel(new FlowLayout()); panel.add(new JLabel("Field 1")); panel.add(comboBox); panel.add(new JLabel("Field 2")); panel.add(new JTextField(10)); panel.add(new JLabel("Field 3")); panel.add(new JTextField(10)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); Container c = frame.getContentPane(); c.setLayout(new BorderLayout()); c.add(panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String title = (args.length == 0 ? "CheckBox Sample" : args[0]); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); panel.setBorder(border);//from w w w. j a v a 2s .c o m JCheckBox check = new JCheckBox("Anchovies"); panel.add(check); check = new JCheckBox("Garlic"); panel.add(check); check = new JCheckBox("Onions"); panel.add(check); check = new JCheckBox("Pepperoni"); panel.add(check); check = new JCheckBox("Spinach"); panel.add(check); JButton button = new JButton("Submit"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Cornering Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("+"); JLabel bigLabel = new JLabel("A"); bigLabel.setPreferredSize(new Dimension(400, 400)); bigLabel.setBorder(new LineBorder(Color.red)); JScrollPane scrollPane = new JScrollPane(bigLabel); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, button); scrollPane.setColumnHeaderView(new JLabel("B")); scrollPane.setRowHeaderView(new JLabel("C")); ActionListener actionListener = new JScrollPaneToTopAction(scrollPane); button.addActionListener(actionListener); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200);// www . j a v a2s . com frame.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);//from w ww . j a v a2 s . co 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.USE_SELECTION); 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);// ww w . j a va2 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);//from w ww .j a v a 2 s . co 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); }