List of usage examples for java.awt BorderLayout BorderLayout
public BorderLayout()
From source file:Main.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override//from w w w. j a v a2 s . c om public void run() { try { Image img = null; img = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new ImagePanel(img)); frame.pack(); frame.setVisible(true); } catch (Exception exp) { exp.printStackTrace(); } } }); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JTextPane codearea = new JTextPane(); JScrollPane scroll;//from www. java 2s . c om scroll = new JScrollPane(codearea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setPreferredSize(new Dimension(300, 300)); JPanel panel = new JPanel(new BorderLayout()); panel.add(scroll, BorderLayout.CENTER); JButton comp = new JButton("Print text"); comp.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(codearea.getText()); } }); panel.add(comp, BorderLayout.SOUTH); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[][] data = { { "Data", "Data" } }; String[] col = { "Col", "Col" }; final DefaultTableModel model = new DefaultTableModel(data, col); JTable table = new JTable(model); JButton addRow = new JButton("Add Empty Row"); addRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.addRow(new Object[] {}); }/*from w w w . j av a2 s .c o m*/ }); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JScrollPane(table)); panel.add(addRow, BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, panel); }
From source file:SpinnerDateStartEndSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Calendar cal = Calendar.getInstance(); Date now = cal.getTime();//from ww w . ja v a 2 s .c o m cal.add(Calendar.YEAR, -50); Date startDate = cal.getTime(); cal.add(Calendar.YEAR, 100); Date endDate = cal.getTime(); SpinnerModel model = new SpinnerDateModel(now, startDate, endDate, Calendar.YEAR); JSpinner spinner1 = new JSpinner(model); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextPane text = new JTextPane() { @Override/*from w ww. j a v a 2s . co m*/ public String getToolTipText() { return ((JComponent) getParent()).getToolTipText(); } @Override public String getToolTipText(MouseEvent event) { return ((JComponent) getParent()).getToolTipText(event); } }; text.setText("Lorem ipsum dolor sit"); ToolTipManager.sharedInstance().registerComponent(text); JFrame frame = new JFrame("Testing"); JPanel panel = new JPanel(new BorderLayout()); panel.setToolTipText("tooltip from parent"); frame.setContentPane(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(text); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextPane tp = new JTextPane(); JButton withFocus = new JButton("Select with focus"); tp.addMouseListener(new MouseAdapter() { @Override//from ww w . j av a 2 s. c o m public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) { tp.selectAll(); } } }); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tp)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:CaretSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Caret Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); content.add(scrollPane, BorderLayout.CENTER); final JTextField dot = new JTextField(); dot.setEditable(false);/*from w w w . j av a2s. c o m*/ JPanel dotPanel = new JPanel(new BorderLayout()); dotPanel.add(new JLabel("Dot: "), BorderLayout.WEST); dotPanel.add(dot, BorderLayout.CENTER); content.add(dotPanel, BorderLayout.NORTH); final JTextField mark = new JTextField(); mark.setEditable(false); JPanel markPanel = new JPanel(new BorderLayout()); markPanel.add(new JLabel("Mark: "), BorderLayout.WEST); markPanel.add(mark, BorderLayout.CENTER); content.add(markPanel, BorderLayout.SOUTH); CaretListener listener = new CaretListener() { public void caretUpdate(CaretEvent caretEvent) { dot.setText("" + caretEvent.getDot()); mark.setText("" + caretEvent.getMark()); } }; textArea.addCaretListener(listener); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JButton btnA = new JButton("A"); JButton btnB = new JButton("B"); btnA.setPreferredSize(new Dimension(50, 25)); btnB.setPreferredSize(new Dimension(100, 25)); JPanel btnAPanel = new JPanel(); JPanel btnBPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); btnAPanel.add(btnA);/*from ww w . ja v a2s . c om*/ btnBPanel.add(btnB); JPanel topPanel = new JPanel(new GridLayout(1, 0)); topPanel.add(new JLabel("hi")); topPanel.add(btnAPanel); topPanel.add(btnBPanel); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(topPanel, BorderLayout.NORTH); mainPanel.setPreferredSize(new Dimension(400, 300)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(mainPanel); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Calendar cal = Calendar.getInstance(); Date now = cal.getTime();//w w w. j av a2 s . co m cal.add(Calendar.YEAR, -50); Date startDate = cal.getTime(); cal.add(Calendar.YEAR, 100); Date endDate = cal.getTime(); SpinnerModel model2 = new SpinnerDateModel(now, startDate, endDate, Calendar.YEAR); JSpinner spinner2 = new JSpinner(model2); JLabel label2 = new JLabel("Range"); JPanel panel2 = new JPanel(new BorderLayout()); panel2.add(label2, BorderLayout.WEST); panel2.add(spinner2, BorderLayout.CENTER); frame.add(panel2, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
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" }); }// www. j av a 2s . co 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); }