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) { Object[][] rowData = { { "Hello", "World" } }; Object[] columnNames = { "A", "B" }; JTable table;//from w w w .j av a2 s.co m DefaultTableModel model; model = new DefaultTableModel(rowData, columnNames); table = new JTable(); table.setModel(model); JButton add = new JButton("Add"); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.addRow(rowData[0]); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(add, BorderLayout.SOUTH); c.add(new JScrollPane(table), BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:MyCellRenderer.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list = new JList(new String[] { "A", "B", "C" }); list.setCellRenderer(new MyCellRenderer()); frame.add(new JScrollPane(list)); frame.setSize(300, 200);/* ww w . j av a2 s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int TIMER_DELAY = 2000; String[] data = { "A", "B", "C", "D" }; DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(data); JComboBox<String> combobox = new JComboBox<>(model); JList<String> jlist = new JList<>(model); new Timer(TIMER_DELAY, new ActionListener() { private int count = 0; public void actionPerformed(ActionEvent e) { model.addElement("count: " + count); count++;/*from w w w. j a v a 2s . c om*/ } }).start(); JPanel comboPanel = new JPanel(); comboPanel.add(combobox); JPanel listPanel = new JPanel(); listPanel.add(new JScrollPane(jlist)); JPanel panel = new JPanel(new GridLayout(1, 0)); panel.add(comboPanel); panel.add(listPanel); panel.setPreferredSize(new Dimension(400, 200)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(panel); f.pack(); 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);/*w w w .j av a 2 s . co 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:ResizeTable.java
public static void main(String args[]) { Object rowData[][] = { { "1", "one", "ichi - \u4E00", "un", "I" }, { "2", "two", "ni - \u4E8C", "deux", "II" }, { "3", "three", "san - \u4E09", "trois", "III" }, { "4", "four", "shi - \u56DB", "quatre", "IV" }, { "5", "five", "go - \u4E94", "cinq", "V" }, { "6", "six", "roku - \u516D", "treiza", "VI" }, { "7", "seven", "shichi - \u4E03", "sept", "VII" }, { "8", "eight", "hachi - \u516B", "huit", "VIII" }, { "9", "nine", "kyu - \u4E5D", "neur", "IX" }, { "10", "ten", "ju - \u5341", "dix", "X" } }; String columnNames[] = { "#", "English", "Japanese", "French", "Roman" }; final JTable table = new JTable(rowData, columnNames); JScrollPane scrollPane = new JScrollPane(table); String modes[] = { "Resize All Columns", "Resize Last Column", "Resize Next Column", "Resize Off", "Resize Subsequent Columns" }; 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 }; JComboBox resizeModeComboBox = new JComboBox(modes); int defaultMode = 4; table.setAutoResizeMode(modeKey[defaultMode]); resizeModeComboBox.setSelectedIndex(defaultMode); ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { JComboBox source = (JComboBox) e.getSource(); int index = source.getSelectedIndex(); table.setAutoResizeMode(modeKey[index]); }/*from w w w . j a va 2 s .c o m*/ }; resizeModeComboBox.addItemListener(itemListener); JFrame frame = new JFrame("Resizing Table"); Container contentPane = frame.getContentPane(); contentPane.add(resizeModeComboBox, BorderLayout.NORTH); contentPane.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { DefaultTableModel model = new DefaultTableModel() { public Class getColumnClass(int mColIndex) { int rowIndex = 0; Object o = getValueAt(rowIndex, mColIndex); if (o == null) { return Object.class; } else { return o.getClass(); }/* w w w . j a v a 2s. com*/ } }; JTable table = new JTable(model); model.addColumn("Col1", new Object[] { Color.red }); model.addRow(new Object[] { Color.green }); model.addRow(new Object[] { Color.blue }); table.setDefaultRenderer(Color.class, new ColorTableCellRenderer()); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.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" }; JFrame frame = new JFrame("Tooltip Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JLabel headerRenderer = new DefaultTableCellRenderer(); String columnName = table.getModel().getColumnName(0); headerRenderer.setText(columnName);/*ww w. j a v a2 s .c om*/ headerRenderer.setToolTipText("Wave"); TableColumnModel columnModel = table.getColumnModel(); TableColumn column = columnModel.getColumn(0); column.setHeaderRenderer((TableCellRenderer) headerRenderer); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeEdit.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; JTree tree = new JTree(array); tree.setEditable(true);/*from w ww .ja v a 2 s .co m*/ tree.setRootVisible(true); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); String elements[] = { "A", "B", "C", "D" }; JComboBox comboBox = new JComboBox(elements); comboBox.setEditable(true); TreeCellEditor comboEditor = new DefaultCellEditor(comboBox); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); 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);/*from w w w. j av a 2 s .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:SetViewportPosition.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);/*from w ww . jav a2 s . com*/ 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); scrollPane.getViewport().setViewPosition(new Point(0, 0)); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }