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[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);
    JScrollPane scrollingList = new JScrollPane(list);

    // The default layout orientation is JList.VERTICAL
    int orient = list.getLayoutOrientation();

    // Change the layout orientation to left-to-right, top-to-bottom
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
}

From source file:Main.java

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

    JFrame f = new JFrame();
    f.add(new JScrollPane(tree));
    f.setSize(300, 300);/*from   w  w w  . j  a v a2  s. com*/
    f.setVisible(true);

    // Get paths of all selected nodes
    TreePath[] paths = tree.getSelectionPaths();

}

From source file:Main.java

public static void main(String[] argv) {
    // Create a table with 10 rows and 5 columns
    JTable table = new JTable(10, 5);

    // Make the table vertically scrollable
    JScrollPane scrollPane = new JScrollPane(table);

}

From source file:Main.java

public static void main(String[] args) {
    JComboBox<Country> countryBox = new JComboBox<Country>(Country.values());
    JOptionPane.showMessageDialog(null, new JScrollPane(countryBox));
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable t = new JTable(10, 1);
    frame.add(new JScrollPane(t));

    t.getSelectionModel().clearSelection();
    t.getSelectionModel().addSelectionInterval(5, 6);
    t.getSelectionModel().addSelectionInterval(8, 8);
    frame.pack();/*from w w  w. j  a  v  a2s .  co  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel image = new JLabel("java2s.com");
    image.setPreferredSize(new Dimension(2000, 2000));
    JScrollPane js = new JScrollPane(image);

    js.setPreferredSize(new Dimension(200, 200));

    JOptionPane.showMessageDialog(null, js);

}

From source file:Main.java

public static void main(String[] args) {
    String[] items = { "1|9|2", "1|9|1", "1|4|7" };
    JList list = new JList(items);
    JPanel panel = new JPanel();
    panel.add(new JScrollPane(list));
    JOptionPane.showMessageDialog(null, panel);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String url = "http://www.yahoo.com";
    JEditorPane editor = new JEditorPane(url);
    editor.setEditable(false);// w w  w.j  ava2s .  c om
    JScrollPane pane = new JScrollPane(editor);
    JFrame f = new JFrame("HTML Demo");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(pane);
    f.setSize(800, 600);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JEditorPane editor = new JEditorPane("text/html", "<H1>A!</H1><P><FONT COLOR=blue>blue</FONT></P>");
    editor.setEditable(false);//from  w w  w. j av a  2 s  .  c  om
    JScrollPane pane = new JScrollPane(editor);
    JFrame f = new JFrame("HTML Demo");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(pane);
    f.setSize(800, 600);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JTextPane textPane = new JTextPane();
    final JScrollPane scrollPane = new JScrollPane(textPane);

    String text = "Lorem ipsum dolor sit amet, " + "consectetur adipiscing elit."
            + "Fusce nec sapien id diam consequat adipiscing.";
    textPane.setText(text);/* w  w w.  j a  v  a  2 s  .c om*/

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(scrollPane);

    frame.setSize(new Dimension(200, 200));
    frame.setVisible(true);

    FontMetrics metrics = textPane.getFontMetrics(textPane.getFont());
    textPane.setMargin(new Insets(scrollPane.getViewport().getHeight() - metrics.getHeight(), 0, 0, 0));
}