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) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextPane newsTextPane = new JTextPane();
    newsTextPane.setEditable(false);//from w  w w .j  av  a 2  s.com

    JScrollPane scrollPane = new JScrollPane(newsTextPane);

    frame.add(scrollPane);
    frame.setSize(300, 250);
    frame.setVisible(true);

    System.out.println("Height : " + scrollPane.getViewport().getSize().height + "\nWidth :"
            + scrollPane.getViewport().getSize().width);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("SplitPaneFrame");

    JLabel leftImage = new JLabel(new ImageIcon("a.gif"));
    Component left = new JScrollPane(leftImage);
    JLabel rightImage = new JLabel(new ImageIcon("b.gif"));
    Component right = new JScrollPane(rightImage);

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
    split.setDividerLocation(100);//from   w ww .j av a2  s .  co m
    frame.getContentPane().add(split);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        list.add("Hello, World " + i);
    }/*  w  w w.  j a  v a2s.co m*/
    JScrollPane pane = new JScrollPane(new JList(list.toArray())) {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(200, 250);
        }
    };
    JOptionPane.showMessageDialog(null, pane);
}

From source file:Main.java

public static void main(String[] args) throws InterruptedException {
    JFrame f = new JFrame();

    DefaultTableModel m = new DefaultTableModel();
    JTable t = new JTable(m);

    f.add(new JScrollPane(t), BorderLayout.CENTER);
    f.setVisible(true);/*from   w  w w. j a v  a2  s  .  co  m*/
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    m.addColumn("A");
    m.addRow(new String[] { "A1" });

    Thread.sleep(2000);

    m.addColumn("B");
    m.addRow(new String[] { "A2", "B2" });
}

From source file:Main.java

public static void main(String[] args) {
    String text = "one\ntwo\nthree\nfour\nfive";
    JFrame frame = new JFrame("title");
    JTextArea textArea = new JTextArea(text, 1, 30); // shows only one line
    JScrollPane scrollPane = new JScrollPane(textArea);
    frame.add(scrollPane);// w  ww  .j a v  a 2s .c o m
    frame.pack();
    frame.setVisible(true);

    final JViewport viewport = scrollPane.getViewport();

    textArea.addCaretListener(e -> {
        System.out.println("First : " + viewport.getViewPosition());
        System.out.println("Second: " + viewport.getViewPosition());
    });
    textArea.setCaretPosition(text.length());
}

From source file:Main.java

License:asdf

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

    JEditorPane editorPane = new JEditorPane();
    editorPane.setText("asdf");

    JScrollPane scrollPane = new JScrollPane(editorPane);
    frame.add(scrollPane);//www.j  av  a2 s.  co  m

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

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    ImageIcon ii = new ImageIcon("largeJava2sLogo.gif");
    JScrollPane jsp = new JScrollPane(new ScrollableLabel(ii));
    f.getContentPane().add(jsp);/*from  ww  w  .  ja v a2 s  . com*/
    f.setSize(300, 250);
    f.setVisible(true);

}

From source file:JDK6TextComponentDemo.java

public static void main(String[] args) throws Exception {
    final JTextArea textArea = new JTextArea();
    textArea.setText("text");
    JScrollPane jScrollPane = new JScrollPane(textArea);
    final MessageFormat header = new MessageFormat("My Header");
    final MessageFormat footer = new MessageFormat("My Footer");

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(jScrollPane, BorderLayout.CENTER);

    JFrame frame = new JFrame();
    frame.setTitle("Text-component Printing Demo");
    frame.setSize(400, 200);/*from  w  w w. j a  v a2 s  .co m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setContentPane(contentPane);
    frame.setVisible(true);
    textArea.print(header, footer, true, null, null, true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(new String[][] { { "One" }, { "Two" }, { "Three" } }, new String[] { "Ordinal" });
    table.addRowSelectionInterval(1, 1);
    f.add(new JScrollPane(table));
    f.pack();/* w  w w.  j  av  a  2  s.  c o m*/
    f.setLocationRelativeTo(null);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);

    JFrame f = new JFrame();
    f.setSize(300, 300);//from  ww  w . ja v  a  2 s . c  om
    f.add(new JScrollPane(table));
    f.setVisible(true);
}