List of usage examples for javax.swing JScrollPane JScrollPane
public JScrollPane(Component view)
JScrollPane
that displays the contents of the specified component, where both horizontal and vertical scrollbars appear whenever the component's contents are larger than the view. From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Use TextAction"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextArea leftArea = new JTextArea(); final JTextArea rightArea = new JTextArea(); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftArea), new JScrollPane(rightArea)); splitPane.setDividerLocation(.5);/*from www .jav a 2 s .co m*/ JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu menu = new JMenu("Options"); menuBar.add(menu); JMenuItem menuItem; Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction); menuItem = menu.add(readAction); menuItem.setText("Make read-only"); Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction); menuItem = menu.add(writeAction); menuItem.setText("Make writable"); menu.addSeparator(); Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction); menuItem = menu.add(cutAction); menuItem.setText("Cut"); Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction); menuItem = menu.add(copyAction); menuItem.setText("Copy"); Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction); menuItem = menu.add(pasteAction); menuItem.setText("Paste"); frame.add(splitPane, BorderLayout.CENTER); frame.setSize(400, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.getContentPane().setLayout(new BorderLayout()); MyTableModel model = new MyTableModel(); JTable table = new JTable(model); table.setRowHeight(80);//from w w w .ja v a 2 s . c om table.getColumnModel().getColumn(0).setCellRenderer(new ImageRenderer()); JScrollPane pane = new JScrollPane(table); frame.getContentPane().add(BorderLayout.CENTER, pane); frame.setSize(500, 400); frame.setVisible(true); }
From source file:HeaderlessSample.java
public static void main(String args[]) { Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" }, { "Row2-Column1", "Row2-Column2", "Row2-Column3" } }; Object columnNames[] = { "Column 1", "Column 2", "Column 3" }; // JTable table = new HeaderlessTable(rowData, columnNames); JTable table = new JTable(rowData, columnNames); table.setTableHeader(null);/*from w w w . ja va2 s .co m*/ JScrollPane scrollPane = new JScrollPane(table); // scrollPane.setColumnHeaderView(null); JFrame frame = new JFrame("Headerless Table"); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTable table = new JTable(5, 5) { @Override//from w w w . j av a 2 s .c o m public Component prepareRenderer(TableCellRenderer renderer, int row, int col) { Component comp = super.prepareRenderer(renderer, row, col); ((JLabel) comp).setHorizontalAlignment(JLabel.RIGHT); return comp; } }; table.setPreferredScrollableViewportSize(table.getPreferredSize()); JScrollPane scrollPane = new JScrollPane(table); JFrame f = new JFrame(); f.getContentPane().add(scrollPane); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DefaultListModel<String> model = new DefaultListModel<>(); JList<String> sList = new JList<>(model); for (int i = 0; i < 100; i++) { model.addElement("String " + i); }//from w w w.j a v a2 s .c o m sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); sList.setVisibleRowCount(-1); sList.setLayoutOrientation(JList.HORIZONTAL_WRAP); JFrame frame = new JFrame("Foo001"); frame.getContentPane().add(new JScrollPane(sList)); frame.getContentPane().setPreferredSize(new Dimension(400, 300)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] ITEMS1 = { "one", "two", "three", "four", "five" }; String[] ITEMS2 = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; JPanel northPanel = new JPanel(); northPanel.add(new JCheckBox("Reminder")); northPanel.add(new JComboBox(ITEMS1)); northPanel.add(new JComboBox(ITEMS2)); JPanel p = new JPanel(new BorderLayout()); p.add(northPanel, BorderLayout.NORTH); p.add(new JScrollPane(new JTextArea(8, 30)), BorderLayout.CENTER); JFrame frame = new JFrame(); frame.getContentPane().add(p);/* ww w . j a va 2s . c o m*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:SelectionModeDemo.java
public static void main(String args[]) { JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(100);//from ww w . jav a 2 s . c o m for (int i = 0; i < 100; i++) { model.addElement(Integer.toString(i)); } JList jlist2 = new JList(model); jlist2.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(Main.class.getSimpleName()); DefaultTreeModel model = getTreeModel(); JTree tree1 = new JTree(model); JTree tree2 = new JTree(model); frame.add(new JScrollPane(tree1), BorderLayout.WEST); frame.add(new JScrollPane(tree2), BorderLayout.EAST); frame.pack();//from w ww. j av a 2 s.c om frame.setSize(frame.getWidth() + 50, frame.getHeight() + 140); frame.setVisible(true); Timer t = new Timer(2000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.add(new DefaultMutableTreeNode("A new node")); model.nodesWereInserted(root, new int[] { root.getChildCount() - 1 }); tree1.expandRow(0); tree2.expandRow(0); frame.revalidate(); } }); t.start(); }
From source file:LabelHeaderSample.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; JFrame frame = new JFrame("Label Header"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String headers[] = { "English", "#" }; JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); JLabel headerRenderer = new DefaultTableCellRenderer(); String columnName = table.getModel().getColumnName(0); headerRenderer.setText(columnName);/*from ww w. jav a 2s . com*/ headerRenderer.setToolTipText("text"); TableColumnModel columnModel = table.getColumnModel(); TableColumn englishColumn = columnModel.getColumn(0); englishColumn.setHeaderRenderer((TableCellRenderer) headerRenderer); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } }; String headers[] = { "Upper", "Lower" }; final int modeKey[] = { JTable.AUTO_RESIZE_ALL_COLUMNS, JTable.AUTO_RESIZE_LAST_COLUMN, JTable.AUTO_RESIZE_NEXT_COLUMN, JTable.AUTO_RESIZE_OFF, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS }; final JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); String modes[] = { "Resize All Columns", "Resize Last Column", "Resize Next Column", "Resize Off", "Resize Subsequent Columns" }; final JComboBox resizeModeComboBox = new JComboBox(modes); int defaultMode = 4; table.setAutoResizeMode(modeKey[defaultMode]); resizeModeComboBox.setSelectedIndex(defaultMode); ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { int index = resizeModeComboBox.getSelectedIndex(); table.setAutoResizeMode(modeKey[index]); }/*from w ww. j a v a 2 s . c o m*/ }; resizeModeComboBox.addItemListener(itemListener); JFrame frame = new JFrame("Resizing Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(resizeModeComboBox, BorderLayout.NORTH); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }