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:SharedDataSample.java
public static void main(String args[]) { final String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; final DefaultComboBoxModel model = new DefaultComboBoxModel(labels); JFrame frame = new JFrame("Shared Data"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel panel = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setMaximumRowCount(5);//w w w. java 2 s .c o m comboBox1.setEditable(true); JComboBox comboBox2 = new JComboBox(model); comboBox2.setMaximumRowCount(5); comboBox2.setEditable(true); panel.add(comboBox1); panel.add(comboBox2); contentPane.add(panel, BorderLayout.NORTH); JList jlist = new JList(model); JScrollPane scrollPane = new JScrollPane(jlist); contentPane.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); contentPane.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int index = (int) (Math.random() * labels.length); model.addElement(labels[index]); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:RowSorterDemo.java
public static void main(String args[]) { JFrame frame = new JFrame("Sort Table Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object rows[][] = { { "J", 23 }, { "R", 24, }, { "E", 21, }, { "B", 27, }, { "A", 25, }, { "S", 22, }, }; String columns[] = { "Name", "Age" }; TableModel model = new DefaultTableModel(rows, columns) { public Class getColumnClass(int column) { Class returnValue;//from ww w .ja v a 2 s .c o m if ((column >= 0) && (column < getColumnCount())) { returnValue = getValueAt(0, column).getClass(); } else { returnValue = Object.class; } return returnValue; } }; JTable table = new JTable(model); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:DragDropList.java
public static void main(String[] a) { JFrame f = new JFrame(); f.add(new JScrollPane(new DragDropList())); f.setSize(300, 300);//from w ww .ja v a 2s . c o m f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { DefaultTableModel model = new DefaultTableModel() { public Class getColumnClass(int columnIndex) { Object o = getValueAt(0, columnIndex); if (o == null) { return Object.class; } else { return o.getClass(); }/*from ww w . j a va2 s. c o m*/ } }; JTable table = new JTable(model); model.addColumn("Boolean", new Object[] { Boolean.TRUE }); model.addColumn("Date", new Object[] { new Date() }); model.addColumn("Double", new Object[] { new Double(Math.PI) }); model.addColumn("Float", new Object[] { new Float(1.2) }); model.addColumn("Icon", new Object[] { new ImageIcon("icon.gif") }); model.addColumn("Number", new Object[] { new Integer(1) }); model.addColumn("Object", new Object[] { "object" }); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:EditableTable.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String[] columnTitles = { "First Name", "Last Name", "Weight (lb)", "Blood Group", "Age>20yrs" }; Object[][] dataEntries = { { "Saravan", "Pantham", new Integer(50), "B", new Boolean(false) }, { "Eric", "", new Integer(180), "O", new Boolean(true) }, { "John", "", new Integer(120), "AB", new Boolean(false) }, { "Mathew", "", new Integer(140), "A", new Boolean(true) }, }; TableModel model = new EditableTableModel(columnTitles, dataEntries); JTable table = new JTable(model); table.createDefaultColumnsFromModel(); String[] bloodGroups = { "A", "B", "AB", "O" }; JComboBox comboBox = new JComboBox(bloodGroups); table.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox)); frame.add(new JScrollPane(table)); frame.setSize(300, 200);//from w w w.j a va 2 s . c o m frame.setVisible(true); }
From source file:FileTableDemo.java
public static void main(String[] args) { // Figure out what directory to display; File dir;//from w ww. j a va2 s . c o m if (args.length > 0) dir = new File(args[0]); else dir = new File(System.getProperty("user.home")); // Create a TableModel object to represent the contents of the directory FileTableModel model = new FileTableModel(dir); // Create a JTable and tell it to display our model JTable table = new JTable(model); // Display it all in a scrolling window and make the window appear JFrame frame = new JFrame("FileTableDemo"); frame.getContentPane().add(new JScrollPane(table), "Center"); frame.setSize(600, 400); frame.setVisible(true); }
From source file:TreeNodeVector.java
public static void main(final String args[]) { UIManager.put("Tree.openIcon", new ImageIcon("yourFile.gif")); 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 ww w . j ava 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:Main.java
public static void main(String[] args) { Node root = new Node("Root"); fillTree(root, 5, "tree label"); DefaultTreeModel model = new DefaultTreeModel(root); JTree tree = new JTree(model); ToolTipManager.sharedInstance().registerComponent(tree); tree.setCellRenderer(new MyTreeCellRenderer()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(tree)); f.pack();/*from w ww .j av a 2 s .co m*/ f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument doc = new DefaultStyledDocument(); JTextPane textPane = new JTextPane(doc); textPane.setText("this is a test."); Random random = new Random(); for (int i = 0; i < textPane.getDocument().getLength(); i++) { SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setForeground(set, new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256))); StyleConstants.setFontSize(set, random.nextInt(12) + 12); StyleConstants.setBold(set, random.nextBoolean()); StyleConstants.setItalic(set, random.nextBoolean()); StyleConstants.setUnderline(set, random.nextBoolean()); doc.setCharacterAttributes(i, 1, set, true); }//from www . j a v a2 s . c o m frame.add(new JScrollPane(textPane)); frame.setSize(500, 400); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JTextComponent textcomp = new JTextArea(); final UndoManager undo = new UndoManager(); Document doc = textcomp.getDocument(); doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); }/*from w w w . j av a 2 s .c o m*/ }); textcomp.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException e) { } } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(textcomp)); frame.setSize(380, 320); frame.setLocationRelativeTo(null); frame.setVisible(true); }