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:Main.java
public static void main(String[] args) { Main testJFrame = new Main(); List<String> columns = new ArrayList<String>(); List<String[]> values = new ArrayList<String[]>(); columns.add("col1"); columns.add("col2"); columns.add("col3"); for (int i = 0; i < 100; i++) { values.add(new String[] { "val" + i + " col1", "val" + i + " col2", "val" + i + " col3" }); }/*from w w w .j a v a 2 s . c o m*/ TableModel tableModel = new DefaultTableModel(values.toArray(new Object[][] {}), columns.toArray()); JTable table = new JTable(tableModel); testJFrame.setLayout(new BorderLayout()); testJFrame.add(new JScrollPane(table), BorderLayout.CENTER); testJFrame.add(table.getTableHeader(), BorderLayout.NORTH); testJFrame.setVisible(true); testJFrame.setSize(200, 200); }
From source file:TryBorderLayout.java
public static void main(String[] args) { JFrame aWindow = new JFrame("This is a Border Layout"); aWindow.setBounds(30, 30, 300, 300); // Size aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BorderLayout border = new BorderLayout(); // Create a layout manager Container content = aWindow.getContentPane(); // Get the content pane content.setLayout(border); // Set the container layout mgr EtchedBorder edge = new EtchedBorder(EtchedBorder.RAISED); // Button border // Now add five JButton components and set their borders JButton button;//from w w w . jav a 2 s . c o m content.add(button = new JButton("EAST"), BorderLayout.EAST); button.setBorder(edge); content.add(button = new JButton("WEST"), BorderLayout.WEST); button.setBorder(edge); content.add(button = new JButton("NORTH"), BorderLayout.NORTH); button.setBorder(edge); content.add(button = new JButton("SOUTH"), BorderLayout.SOUTH); button.setBorder(edge); content.add(button = new JButton("CENTER"), BorderLayout.CENTER); button.setBorder(edge); aWindow.setVisible(true); // Display the window }
From source file:KeyTester.java
public static void main(String args[]) { String actionKey = "theAction"; JFrame f = new JFrame("Key Tester"); JButton jb1 = new JButton("<html><center>B<br>Focused/Typed"); JButton jb2 = new JButton("<html><center>Ctrl-C<br>Window/Pressed"); JButton jb3 = new JButton("<html><center>Shift-D<br>Ancestor/Released"); Container pane = f.getContentPane(); pane.add(jb1, BorderLayout.NORTH); pane.add(jb2, BorderLayout.CENTER); pane.add(jb3, BorderLayout.SOUTH); KeyStroke stroke = KeyStroke.getKeyStroke("typed B"); Action action = new MyActionListener("Action Happened"); // Defaults to JComponent.WHEN_FOCUSED map InputMap inputMap = jb1.getInputMap(); inputMap.put(stroke, actionKey);/*from ww w.ja v a 2 s . co m*/ ActionMap actionMap = jb1.getActionMap(); actionMap.put(actionKey, action); stroke = KeyStroke.getKeyStroke("ctrl C"); action = new MyActionListener("Action Didn't Happen"); inputMap = jb2.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, actionKey); actionMap = jb2.getActionMap(); actionMap.put(actionKey, action); stroke = KeyStroke.getKeyStroke("shift released D"); action = new MyActionListener("What Happened?"); inputMap = jb3.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(stroke, actionKey); actionMap = jb3.getActionMap(); actionMap.put(actionKey, action); f.setSize(200, 200); f.show(); }
From source file:DragLabel.java
public static void main(String args[]) { JFrame frame = new JFrame("Drag Label"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Hello, World"); label.setTransferHandler(new TransferHandler("foreground")); MouseListener listener = new MouseAdapter() { public void mousePressed(MouseEvent me) { JComponent comp = (JComponent) me.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, me, TransferHandler.COPY); }/*from w ww .jav a 2s. c om*/ }; label.addMouseListener(listener); frame.add(label, BorderLayout.SOUTH); JTextField text = new JTextField(); frame.add(text, BorderLayout.NORTH); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame("Test"); KeyboardFocusManager.getCurrentKeyboardFocusManager().addVetoableChangeListener("focusedWindow", new VetoableChangeListener() { private boolean gained = false; @Override/*from ww w. j av a 2 s . com*/ public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { if (evt.getNewValue() == frame) { gained = true; } if (gained && evt.getNewValue() != frame) { frame.dispose(); } } }); frame.add(new JTextField(10), BorderLayout.NORTH); frame.add(new JTextField(10), BorderLayout.SOUTH); frame.pack(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { final JTextField textField = new JTextField(); JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); BoundedRangeModel brm = textField.getHorizontalVisibility(); scrollBar.setModel(brm);/*from ww w.j a va2s. co m*/ panel.add(textField); panel.add(scrollBar); textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Text: " + textField.getText()); } }); JFrame frame = new JFrame("Text Slider"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel, BorderLayout.NORTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:MainClass.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 ww .j a va 2 s .c om*/ } catch (NumberFormatException e) { returnValue = false; } return returnValue; } }; textField1.setInputVerifier(verifier); textField3.setInputVerifier(verifier); frame.add(textField1, BorderLayout.NORTH); frame.add(textField2, BorderLayout.CENTER); frame.add(textField3, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:FormattedSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("Formatted Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd"); DateFormatter displayFormatter = new DateFormatter(displayFormat); DateFormat editFormat = new SimpleDateFormat("MM/dd/yy"); DateFormatter editFormatter = new DateFormatter(editFormat); DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);/* w w w. j a v a 2s . com*/ JFormattedTextField date2TextField = new JFormattedTextField(factory, new Date()); frame.add(date2TextField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JFormattedTextField source = (JFormattedTextField) actionEvent.getSource(); Object value = source.getValue(); System.out.println("Class: " + value.getClass()); System.out.println("Value: " + value); } }; date2TextField.addActionListener(actionListener); frame.add(new JTextField(), BorderLayout.SOUTH); frame.setSize(250, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Formatted Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd"); DateFormatter displayFormatter = new DateFormatter(displayFormat); DateFormat editFormat = new SimpleDateFormat("MM/dd/yy"); DateFormatter editFormatter = new DateFormatter(editFormat); DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);/* ww w . j ava 2 s . c o m*/ JFormattedTextField date2TextField = new JFormattedTextField(factory, new Date()); frame.add(date2TextField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JFormattedTextField source = (JFormattedTextField) actionEvent.getSource(); Object value = source.getValue(); System.out.println("Class: " + value.getClass()); System.out.println("Value: " + value); } }; date2TextField.addActionListener(actionListener); frame.add(new JTextField(), BorderLayout.SOUTH); frame.setSize(250, 100); frame.setVisible(true); }
From source file:TextSlider.java
public static void main(String args[]) { JFrame frame = new JFrame("Text Slider"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextField textField = new JTextField(); JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); BoundedRangeModel brm = textField.getHorizontalVisibility(); scrollBar.setModel(brm);/* w w w .j a va 2 s. c om*/ panel.add(textField); panel.add(scrollBar); final TextSlider ts = new TextSlider(); textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Text: " + textField.getText()); } }); frame.add(panel, BorderLayout.NORTH); frame.setSize(300, 100); frame.setVisible(true); }