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(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000);/* w ww .ja va 2 s . co m*/ for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { model.addElement(labels[j]); } } JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton( new UndoAction(manager, (String) UIManager.get("AbstractUndoableEdit.undoText"))); toolbar.add(undoButton);// w w w .j a v a2 s. c om JButton redoButton = new JButton( new RedoAction(manager, (String) UIManager.get("AbstractUndoableEdit.redoText"))); toolbar.add(redoButton); Container content = frame.getContentPane(); content.add(toolbar, BorderLayout.NORTH); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000);//from w w w .ja va2 s. c o m for (int j = 0; j < 5; j++) { model.addElement(labels[j]); } System.out.println(model.toArray().length); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:ModifyModelSampleModelAction.java
public static void main(String args[]) { JFrame frame = new JFrame("Modifying Model"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Fill model final DefaultListModel model = new DefaultListModel(); for (int i = 0, n = labels.length; i < n; i++) { model.addElement(labels[i]);//from w w w . java 2 s . c om } JList jlist = new JList(model); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); JButton jb = new JButton("add F"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.add(0, "First"); model.clear(); model.addElement("Last"); model.addElement("Last"); model.addElement("Last"); model.addElement("Last"); int size = model.getSize(); model.insertElementAt("Middle", size / 2); model.set(0, "New First"); model.setElementAt("New Last", size - 1); model.remove(0); // model.removeAllElements(); // model.removeElement("Last"); // model.removeElementAt(size / 2); // model.removeRange(0, size / 2); } }); frame.add(jb, BorderLayout.SOUTH); frame.setSize(640, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] arg) { DefaultListModel<String> listModel = new DefaultListModel<String>(); for (int i = 0; i < 10; i++) { listModel.addElement("Item " + (i + 1)); }// www .j a v a 2 s . c o m JList<String> list = new JList<String>(listModel); list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (SwingUtilities.isRightMouseButton(me)) { list.clearSelection(); } } }); JScrollPane listScrollPane = new JScrollPane(list); JFrame f = new JFrame(); f.getContentPane().add(listScrollPane); f.setSize(500, 400); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Custom Tip Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Main list = new Main(); JScrollPane scrollPane = new JScrollPane(list); frame.add(scrollPane);/* ww w .jav a2 s . c o m*/ frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] listValues = { "Click", "To", "Add", "New", "Values" }; DefaultListModel<String> model = new DefaultListModel<>(); for (String s : listValues) { model.addElement(s);//www. j a v a 2 s. c o m } JList<String> list = new JList<>(model); MouseListener addListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { model.addElement("aa"); } }; list.addMouseListener(addListener); JOptionPane.showMessageDialog(null, new JScrollPane(list)); }
From source file:JTableSortDemo.java
public static void main(String[] args) { Object[][] data = { { "A", 5 }, { "B", 2 }, { "C", 4 }, { "D", 8 } }; String columnNames[] = { "Item", "Value" }; TableModel model = new DefaultTableModel(data, columnNames) { public Class<?> getColumnClass(int column) { return getValueAt(0, column).getClass(); }//w w w .j a va 2s.c om }; JTable table = new JTable(model); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); JScrollPane scrollPane = new JScrollPane(table); JFrame frame = new JFrame("Sorting Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(scrollPane); frame.setSize(300, 200); frame.setVisible(true); }
From source file:UseActions.java
public static void main(String args[]) { JFrame frame = new JFrame("Use TextAction"); Container contentPane = frame.getContentPane(); Dimension empty = new Dimension(0, 0); final JTextArea leftArea = new JTextArea(); JScrollPane leftScrollPane = new JScrollPane(leftArea); leftScrollPane.setPreferredSize(empty); final JTextArea rightArea = new JTextArea(); JScrollPane rightScrollPane = new JScrollPane(rightArea); rightScrollPane.setPreferredSize(empty); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar);/*from ww w .j av a2 s .c o m*/ 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"); contentPane.add(splitPane, BorderLayout.CENTER); frame.setSize(400, 250); frame.setVisible(true); splitPane.setDividerLocation(.5); }
From source file:Main.java
public static void main(String[] args) { Object[][] rowData = {};/*from w w w .j a v a 2 s. c o m*/ Object[] columnNames = { "Column 1", "Column 2", "Column 3" }; DefaultTableModel listTableModel; listTableModel = new DefaultTableModel(rowData, columnNames); for (int i = 1; i < 25; i++) { String rowString = "Quiz #" + i; listTableModel.addRow(new Object[] { rowString, "ICON", "ICON" }); } JTable listTable; listTable = new JTable(listTableModel); listTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); listTable.setCellEditor(null); listTable.setBounds(37, 143, 397, 183); JFrame frame = new JFrame(); frame.add(new JScrollPane(listTable)); frame.setVisible(true); frame.pack(); }