Example usage for javax.swing JScrollPane JScrollPane

List of usage examples for javax.swing JScrollPane JScrollPane

Introduction

In this page you can find the example usage for javax.swing JScrollPane JScrollPane.

Prototype

public JScrollPane(Component view) 

Source Link

Document

Creates a 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.

Usage

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   ww w . j a v a 2  s . c  o m

    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:Main.java

public static void main(String[] args) {
    JTextPane pane = new JTextPane();
    TabStop[] tabs = new TabStop[1];
    tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
    TabSet tabset = new TabSet(tabs);

    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
    pane.setParagraphAttributes(aset, false);
    pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n"
            + "\t200.002\t200.002\t200.002\t200.002\n" + "\t.33\t.33\t.33\t.33\n");

    JFrame frame = new JFrame("TabExample");
    frame.setContentPane(new JScrollPane(pane));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(360, 120);//from   www.j av  a2  s .c om
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("DynamicUtilTreeNode Hashtable");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");

    Hashtable<Object, Object> hashtable = new Hashtable<Object, Object>();
    hashtable.put("A", args);
    hashtable.put("B", new String[] { "a", "b", "c" });
    Hashtable<Object, Object> innerHashtable = new Hashtable<Object, Object>();
    Properties props = System.getProperties();
    innerHashtable.put(props, props);//from  w  w  w .j a  va  2s  . co m
    hashtable.put("C", 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);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JTextPane textPane = new JTextPane();
    textPane.setText("This is a test string");

    StyleConstants.setBold(BOLD, true);

    StyleConstants.setItalic(ITALIC, true);

    int start = 5;
    int end = 10;

    textPane.getStyledDocument().setCharacterAttributes(start, end - start, BOLD, false);
    textPane.getStyledDocument().setCharacterAttributes(start, end - start, ITALIC, false);
    for (int i = start; i < end; i++)
        System.out.println(/*w w w .ja  va2 s.c  om*/
                textPane.getStyledDocument().getCharacterElement(i).getAttributes().containsAttributes(BOLD)); // all now print true

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(textPane));
    frame.pack();
    frame.setVisible(true);
}

From source file:EditorPaneSample.java

public static void main(String args[]) throws IOException {
    JFrame frame = new JFrame("EditorPane Example");
    Container content = frame.getContentPane();

    JEditorPane editorPane = new JEditorPane("http://www.apress.com");
    editorPane.setEditable(false);/*from  ww  w .j  a v a  2  s  . c  o  m*/

    HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(frame, editorPane);
    editorPane.addHyperlinkListener(hyperlinkListener);

    JScrollPane scrollPane = new JScrollPane(editorPane);
    content.add(scrollPane);

    frame.setSize(640, 480);
    frame.setVisible(true);
}

From source file:TablePrintLastVersion.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 www  .j  a va  2  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 {
                MessageFormat headerFormat = new MessageFormat("Page {0}");
                MessageFormat footerFormat = new MessageFormat("- {0} -");
                table.print(JTable.PrintMode.NORMAL, headerFormat, footerFormat, true,
                        new HashPrintRequestAttributeSet(), true);

            } 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) {
    JPanel gui = new JPanel(new BorderLayout(2, 3));

    JPanel buttonConstrsint = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton getQuotesButton = new JButton("Load");
    buttonConstrsint.add(getQuotesButton);
    gui.add(buttonConstrsint, BorderLayout.NORTH);

    getQuotesButton.addActionListener(e -> {
        String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

        Object[][] data = { { "A", "B", "Snowboarding", new Integer(5), new Boolean(false) },
                { "C", "D", "Pool", new Integer(10), new Boolean(false) } };

        JTable table = new JTable(data, columnNames);

        JScrollPane scrollPane = new JScrollPane(table);
        table.setFillsViewportHeight(true);

        gui.add(scrollPane, BorderLayout.CENTER);
        gui.revalidate();/* w ww  . j a  va  2  s  .c  om*/
        gui.repaint();
    });

    JOptionPane jOptionPane = new JOptionPane(gui);

    JDialog dialog = jOptionPane.createDialog(new JFrame(), "title");
    dialog.setSize(200, 200);
    dialog.setVisible(true);
}

From source file:TreeSelectionRow.java

public static void main(String args[]) {
    String title = "JTree Sample";
    JFrame frame = new JFrame(title);
    JTree tree = new JTree();
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            System.out.println("Min: " + treeSource.getMinSelectionRow());
            System.out.println("Max: " + treeSource.getMaxSelectionRow());
            System.out.println("Lead: " + treeSource.getLeadSelectionRow());
            System.out.println("Row: " + treeSource.getSelectionRows()[0]);
        }/*w  w w  .  jav a2 s  .c o m*/
    };
    tree.addTreeSelectionListener(treeSelectionListener);

    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[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    Vector data = model.getDataVector();
    Vector row = (Vector) data.elementAt(1);

    int mColIndex = 0;
    List colData = new ArrayList(table.getRowCount());
    for (int i = 0; i < table.getRowCount(); i++) {
        row = (Vector) data.elementAt(i);
        colData.add(row.get(mColIndex));
    }//  ww  w. j av a 2 s  . c  o  m

    // Append a new column with copied data
    model.addColumn("Col3", colData.toArray());

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:LoadSync.java

public static void main(String args[]) {
    final String filename = "Test.html";
    JFrame frame = new JFrame("Loading/Saving Example");
    Container content = frame.getContentPane();

    final JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);/*from  w  w  w .jav a2 s  . c om*/
    JScrollPane scrollPane = new JScrollPane(editorPane);
    content.add(scrollPane, BorderLayout.CENTER);

    editorPane.setEditorKit(new HTMLEditorKit());

    JPanel panel = new JPanel();

    // Setup actions
    Action loadAction = new AbstractAction() {
        {
            putValue(Action.NAME, "Load");
        }

        public void actionPerformed(ActionEvent e) {
            doLoadCommand(editorPane, filename);
        }
    };
    JButton loadButton = new JButton(loadAction);
    panel.add(loadButton);

    content.add(panel, BorderLayout.SOUTH);

    frame.setSize(250, 150);
    frame.setVisible(true);
}