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(String[] args) {
    JList<String> list = new JList<String>(new String[] { "one", "two", "three", "four", "five" });
    JScrollPane scrollPane = new JScrollPane(list);
    JButton btn = new JButton(new AbstractAction() {
        {/*from  w ww  .j  a  va 2  s. co  m*/
            putValue(NAME, "Select");
        }

        @Override
        public void actionPerformed(ActionEvent evt) {
            list.setSelectedIndex(0);
        }
    });
    JPanel panel = new JPanel();
    panel.add(scrollPane);
    panel.add(btn);
    JOptionPane.showMessageDialog(null, panel);
}

From source file:Main.java

public static void main(String[] argv) {
    DefaultTableModel model = new DefaultTableModel();
    JTable table1 = new JTable(model);
    JTable table2 = new JTable(model);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.add(new JScrollPane(table1));
    splitPane.add(new JScrollPane(table2));

    table1.getColumnModel().removeColumn(table1.getColumnModel().getColumn(0));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root Label");
    root.add(new DefaultMutableTreeNode("Node Label"));

    JTree tree = new JTree(root);

    JFrame f = new JFrame();
    f.add(new JScrollPane(tree));
    f.setSize(300, 300);/*from ww w.  j ava  2s  . c  o  m*/
    f.setVisible(true);

}

From source file:TreeRowHeightCache.java

public static void main(String[] argv) {
    JTree tree = new JTree();

    if (tree.getRowHeight() <= 0) {
        tree.setRowHeight(1);/*from  w w w .j  a v a2  s . co  m*/
    }
    tree.setRowHeight(0);

    JFrame frame = new JFrame("Image");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setSize(380, 320);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JPanel p = new JPanel();

    p.setLayout(new GridLayout(2, 1));
    JList<String> lista = new JList<>(new String[] { "1", "2", "3", "4" });
    p.add(new JScrollPane(lista));
    JComboBox<String> combo = new JComboBox<>();
    for (int i = 0; i < 100; i++) {
        combo.addItem(Integer.toString(i));
        p.add(combo);//from  www .ja v a 2s  .c om
    }

    JFrame f = new JFrame();
    f.getContentPane().add(p, BorderLayout.CENTER);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(200, 200);
    f.setVisible(true);
}

From source file:LoadingWebPageToJEditorPane.java

public static void main(String[] a) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();

    editorPane.setPage(new URL("http://www.java2s.com"));

    frame.add(new JScrollPane(editorPane));

    frame.setSize(300, 200);/*  w w  w.j a  v  a2  s . com*/
    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("Selection Modes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList list1 = new JList(labels);
    JScrollPane sp1 = new JScrollPane(list1);
    sp1.setColumnHeaderView(new JLabel("List"));
    frame.add(sp1, BorderLayout.CENTER);
    frame.setSize(300, 200);/*from  ww  w .ja va2s.  c  om*/
    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.addColumn("Col2");

    JFrame f = new JFrame();
    f.setSize(300, 300);//from w w w .j a  v  a2s.  c  o  m
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector months = new Vector();
    JList list = new JList(months);

    months.addElement("January");
    months.addElement("December");

    frame.add(new JScrollPane(list));

    frame.setSize(300, 200);//from  w  ww  . j av  a  2  s .  c  om
    frame.setVisible(true);
}

From source file:MainClass.java

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

    Box box = Box.createHorizontalBox();

    JTree tree1 = new JTree();
    JScrollPane scrollPane1 = new JScrollPane(tree1);
    tree1.setAutoscrolls(true);//from   w ww.  j ava2  s .  c o  m

    JTree tree2 = new JTree();
    tree2.putClientProperty("JTree.lineStyle", "None");
    JScrollPane scrollPane2 = new JScrollPane(tree2);

    box.add(scrollPane1, BorderLayout.WEST);
    box.add(scrollPane2, BorderLayout.EAST);

    frame.add(box, BorderLayout.CENTER);
    frame.setSize(300, 240);
    frame.setVisible(true);
}