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:ToolTipTreeCellRenderer.java
public static void main(String args[]) { JFrame frame = new JFrame("Tree Tips"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); JTree tree = new JTree(props); ToolTipManager.sharedInstance().registerComponent(tree); TreeCellRenderer renderer = new ToolTipTreeCellRenderer(props); tree.setCellRenderer(renderer);//w w w .j a va 2 s . c o m JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea textArea = new JTextArea(10, 20); final JProgressBar progressBar = new JProgressBar(0, 10); final CounterTask task = new CounterTask(); task.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { progressBar.setValue((Integer) evt.getNewValue()); }/* ww w . ja va2 s .c om*/ } }); JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { task.execute(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { task.cancel(true); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(startButton); buttonPanel.add(cancelButton); JPanel cp = new JPanel(); LayoutManager layout = new BoxLayout(cp, BoxLayout.Y_AXIS); cp.setLayout(layout); cp.add(buttonPanel); cp.add(new JScrollPane(textArea)); cp.add(progressBar); JFrame frame = new JFrame("SwingWorker Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:ColumnModelSample.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; final Object headers[] = { "English", "#" }; JFrame frame = new JFrame("Scrollless Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); TableColumnModelListener tableColumnModelListener = new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent e) { System.out.println("Added"); }/*from w ww . j a v a 2 s . com*/ public void columnMarginChanged(ChangeEvent e) { System.out.println("Margin"); } public void columnMoved(TableColumnModelEvent e) { System.out.println("Moved"); } public void columnRemoved(TableColumnModelEvent e) { System.out.println("Removed"); } public void columnSelectionChanged(ListSelectionEvent e) { System.out.println("Selection Changed"); } }; TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(tableColumnModelListener); columnModel.setColumnMargin(12); TableColumn column = new TableColumn(1); columnModel.addColumn(column); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] m = { "A", "B", "C" }; DefaultMutableTreeNode root = new DefaultMutableTreeNode(new Node("Values")); root.add(new DefaultMutableTreeNode(new Node("Value 1", m))); root.add(new DefaultMutableTreeNode(new Node("Value 2", m))); DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(new Node("Value 3", m)); root.add(leaf);/* ww w . j a v a2s. co m*/ leaf.add(new DefaultMutableTreeNode(new Node("Value 3A", m))); leaf.add(new DefaultMutableTreeNode(new Node("Value 3B", m))); JTree tree = new JTree(root); RendererDispatcher rendererDispatcher = new RendererDispatcher(new JComboBox<String>()); RendererDispatcher editorDispatcher = new RendererDispatcher(new JComboBox<String>()); tree.setCellRenderer(rendererDispatcher); tree.setCellEditor(editorDispatcher); tree.setEditable(true); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(tree)); f.setSize(320, 240); f.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Tab Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); int positions[] = { TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL, TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT }; String strings[] = { "\tTabStop.ALIGN_BAR\n", "\tTabStop.ALIGN_CENTER\n", "\tTabStop.ALIGN_DECIMAL\n", "\tTabStop.ALIGN_LEFT\n", "\tTabStop.ALIGN_RIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); for (int i = 0, n = positions.length; i < n; i++) { TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS); try {//from w w w . j ava2s.c o m int position = document.getLength(); document.insertString(position, strings[i], null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); } catch (BadLocationException badLocationException) { System.err.println("Bad Location"); } } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:SparseTableModel.java
public static void main(String[] a) { String headers[] = { "A", "B" }; TableModel model = new SparseTableModel(10, headers); JTable table = new JTable(model); model.setValueAt("1", 0, 0); model.setValueAt("2", 9, 0); model.setValueAt("3", 5, 1); model.setValueAt("4", 8, 1); JFrame frame = new JFrame("Fixed Column Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(table), BorderLayout.CENTER); frame.setSize(300, 150);//from w ww.j a va 2s .c o m frame.setVisible(true); }
From source file:AppendingTextPane.java
public static void main(String[] args) { try {//from ww w . j a v a 2s . com UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Text Pane with Scrolling Append"); final AppendingTextPane atp = new AppendingTextPane(); f.getContentPane().add(new JScrollPane(atp)); f.setSize(200, 200); f.setVisible(true); // Add some text every second Timer t = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent evt) { String timeString = fmt.format(new Date()); atp.appendText(timeString + "\n"); } SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss"); }); t.start(); }
From source file:TextTabSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Tab Attributes"); Container content = frame.getContentPane(); StyledDocument document = new DefaultStyledDocument(); int positions[] = { TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL, TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT }; String strings[] = { "\tBAR\n", "\tCENTER\n", "\t3.14159265\n", "\tLEFT\n", "\tRIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); for (int i = 0, n = positions.length; i < n; i++) { TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS); try {//from w w w.j a v a 2 s . com int position = document.getLength(); document.insertString(position, strings[i], null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:StylesExample4.java
public static void main(String[] args) { try {/* w ww . ja v a 2 s .co m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Styles Example 4"); // Create the StyleContext, the document and the pane StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); JTextPane pane = new JTextPane(doc); // Create and add the main document style Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); final Style mainStyle = sc.addStyle("MainStyle", defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { // Add the text to the document doc.insertString(0, text, null); // Set the logical style doc.setLogicalStyle(0, mainStyle); } catch (BadLocationException e) { } doc.dump(System.out); } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); }
From source file:SortedListModel.java
public static void main(String args[]) { SortedListModel model = new SortedListModel(); model.add("A"); model.add("C"); model.add("Z"); model.add("B"); JFrame frame = new JFrame("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(model); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); frame.setSize(350, 200);//from www .j a va2 s . co m frame.setVisible(true); }