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:DynamicUtilTreeNodeDemo.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); Hashtable<String, Object> hashtable = new Hashtable<String, Object>(); hashtable.put("Two", new String[] { "A", "B", "C" }); Hashtable<Object, Object> innerHashtable = new Hashtable<Object, Object>(); innerHashtable.put("Two", new String[] { "A", "B", "C" }); hashtable.put("Three", innerHashtable); JTree.DynamicUtilTreeNode.createChildren(root, hashtable); JTree tree = new JTree(root); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150);/*w w w .j av a 2 s. c o m*/ frame.setVisible(true); }
From source file:TreeTips.java
public static void main(String args[]) { JFrame frame = new JFrame("Tree Tips"); Properties props = System.getProperties(); JTree tree = new JTree(props); ToolTipManager.sharedInstance().registerComponent(tree); TreeCellRenderer renderer = new ToolTipTreeCellRenderer(props); tree.setCellRenderer(renderer);//from w w w.ja va 2s . c o m JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.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 ww w .ja va 2 s . co m*/ } JList jlist = new JList(model); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); ListDataListener listDataListener = new ListDataListener() { public void contentsChanged(ListDataEvent listDataEvent) { appendEvent(listDataEvent); } public void intervalAdded(ListDataEvent listDataEvent) { appendEvent(listDataEvent); } public void intervalRemoved(ListDataEvent listDataEvent) { appendEvent(listDataEvent); } private void appendEvent(ListDataEvent listDataEvent) { switch (listDataEvent.getType()) { case ListDataEvent.CONTENTS_CHANGED: System.out.println("Type: Contents Changed"); break; case ListDataEvent.INTERVAL_ADDED: System.out.println("Type: Interval Added"); break; case ListDataEvent.INTERVAL_REMOVED: System.out.println("Type: Interval Removed"); break; } System.out.println(", Index0: " + listDataEvent.getIndex0()); System.out.println(", Index1: " + listDataEvent.getIndex1()); DefaultListModel theModel = (DefaultListModel) listDataEvent.getSource(); System.out.println(theModel); } }; model.addListDataListener(listDataListener); JButton jb = new JButton("add F"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.add(0, "First"); } }); frame.add(jb, BorderLayout.SOUTH); frame.setSize(640, 300); frame.setVisible(true); }
From source file:TableSample.java
public static void main(String args[]) { JFrame f = new JFrame("JTable Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); Object rows[][] = { { "AMZN", "Amazon", "67 9/16" }, { "AOL", "America Online", "68 3/4" }, { "BOUT", "About.com", "56 3/8" }, { "CDNW", "CDnow", "4 7/16" }, { "DCLK", "DoubleClick", "87 3/16" }, { "EBAY", "eBay", "180 7/8" }, { "EWBX", "EarthWeb", "18 1/4" }, { "MKTW", "MarketWatch", "29" }, { "TGLO", "Theglobe.com", "4 15/16" }, { "YHOO", "Yahoo!", "151 1/8" } }; Object columns[] = { "Symbol", "Name", "Price" }; JTable table = new JTable(rows, columns); JScrollPane scrollPane = new JScrollPane(table); content.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200);//from w w w. j a va 2 s .c o m f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Custom Tip Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); PropertiesList list = new PropertiesList(props); JScrollPane scrollPane = new JScrollPane(list); frame.getContentPane().add(scrollPane); frame.setSize(300, 300);/*from w ww .ja v a 2 s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, };//from w w w . j a v a2 s . c o m final Object headers[] = { "English", "#" }; JFrame frame = new JFrame("Table Printing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Print"); ActionListener printAction = new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(); } catch (PrinterException pe) { System.err.println("Error printing: " + pe.getMessage()); } } }; button.addActionListener(printAction); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, };/*from w w w . j a v a 2s . co m*/ final Object headers[] = { "English", "#" }; JFrame frame = new JFrame("Table Printing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Print"); ActionListener printAction = new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(JTable.PrintMode.NORMAL); } catch (PrinterException pe) { System.err.println("Error printing: " + pe.getMessage()); } } }; button.addActionListener(printAction); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setSize(300, 500);/*from w w w.j a v a2 s . c om*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pan = new JPanel(new GridLayout(1, 1)); XmlJTree myTree = new XmlJTree(null); f.add(new JScrollPane(myTree)); JButton button = new JButton("Choose file"); button.addActionListener(e -> { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { myTree.setPath(chooser.getSelectedFile().getAbsolutePath()); } }); pan.add(button); f.add(pan, BorderLayout.SOUTH); f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//from w w w .j a v a2 s . c om DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); comboEditor.stopCellEditing(); 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:MainClass.java
public static void main(String[] args) { JTextArea ta = new JTextArea(); ta.setLineWrap(true);/*w ww . jav a 2s.com*/ ta.setWrapStyleWord(true); JScrollPane scroll = new JScrollPane(ta); ta.append("www.\n"); ta.append("java2s\n"); ta.append(".com"); try { for (int n = 0; n < ta.getLineCount(); n += 1) System.out.println("line " + n + " starts at " + ta.getLineStartOffset(n) + ", ends at " + ta.getLineEndOffset(n)); System.out.println(); int n = 0; while (true) { System.out.print("offset " + n + " is on "); System.out.println("line " + ta.getLineOfOffset(n)); n += 1; } } catch (BadLocationException ex) { System.out.println(ex); } JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scroll, java.awt.BorderLayout.CENTER); f.setSize(150, 150); f.setVisible(true); }