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 {
    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" });

    // Get all the table data
    Vector data = model.getDataVector();

    JFrame f = new JFrame();
    f.setSize(300, 300);/* w w  w  . j  ava 2  s .  co  m*/
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel controlPane = new JPanel();
    JPanel buttonPane = new JPanel();

    controlPane.setLayout(new BoxLayout(controlPane, BoxLayout.PAGE_AXIS));
    controlPane.setPreferredSize(new Dimension(200, 200));
    controlPane.add(new JScrollPane(new JTextArea()));

    buttonPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    buttonPane.setPreferredSize(new Dimension(100, 40));
    buttonPane.add(new JButton("Button1"));
    buttonPane.add(new JButton("Button2"));

    frame.add(controlPane, BorderLayout.NORTH);
    frame.add(buttonPane, BorderLayout.SOUTH);

    frame.pack();//from   w w  w  . j av  a 2  s  .com
    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" });

    // Move the last row to the beginning of the table
    model.moveRow(model.getRowCount() - 1, model.getRowCount() - 1, 0);

    JFrame f = new JFrame();
    f.setSize(300, 300);//w w  w .  ja  va  2 s .  com
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    String[] columnNames = { "Date", "Field", "Home Team", "Visitor Team", "Score" };
    JFrame guiFrame = new JFrame();
    guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    guiFrame.setSize(500, 500);/*from w  w w .  jav a2s .  co  m*/

    JPanel panel = new JPanel();
    panel.setSize(450, 450);
    JLabel titleLabel = new JLabel("OK");
    String[][] data = new String[0][0];
    JTable scheduleTable = new JTable(data, columnNames);
    JScrollPane scrollPane = new JScrollPane(scheduleTable);
    panel.add(scrollPane);
    panel.add(titleLabel);

    guiFrame.add(panel);
    guiFrame.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" });

    // Move the last two rows to the start of the table
    model.moveRow(model.getRowCount() - 2, model.getRowCount() - 1, 0);

    JFrame f = new JFrame();
    f.setSize(300, 300);/*from   w  ww.j  av a2 s. c  o m*/
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    final String START_STRING = "Start\n";
    final int START_STRING_LENGTH = START_STRING.length();

    JFrame frame = new JFrame("Navigation Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextArea textArea = new JTextArea(START_STRING);
    textArea.setCaretPosition(START_STRING_LENGTH);
    JScrollPane scrollPane = new JScrollPane(textArea);
    frame.add(scrollPane, BorderLayout.CENTER);

    NavigationFilter filter = new NavigationFilter() {
        public void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            if (dot < START_STRING_LENGTH) {
                fb.setDot(START_STRING_LENGTH, bias);
            } else {
                fb.setDot(dot, bias);//from  w w  w  .  j  av a2 s  . com
            }
        }

        public void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            if (dot < START_STRING_LENGTH) {
                fb.setDot(START_STRING_LENGTH, bias);
            } else {
                fb.setDot(dot, bias);
            }
        }
    };

    textArea.setNavigationFilter(filter);

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

From source file:Main.java

public static void main(String args[]) {
    JPanel container = new ScrollablePanel();
    container.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
    for (int i = 0; i < 20; ++i) {
        JPanel p = new JPanel();
        p.setPreferredSize(new Dimension(50, 50));
        p.add(new JLabel("" + i));
        container.add(p);/*from www .j a v a2  s  .c  om*/
    }

    JScrollPane scroll = new JScrollPane(container);
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scroll);
    f.pack();
    f.setSize(250, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextArea textArea = new JTextArea(10, 30);
    AbstractDocument doc = (AbstractDocument) textArea.getDocument();
    doc.setDocumentFilter(new EndOfLineFilter());

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(textArea));
    frame.pack();//  w  ww .  j a  va2  s . c om
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sharing Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();
    JTextArea textarea1 = new JTextArea();
    Document document = textarea1.getDocument();
    JTextArea textarea2 = new JTextArea(document);
    JTextArea textarea3 = new JTextArea(document);
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(new JScrollPane(textarea1));
    content.add(new JScrollPane(textarea2));
    content.add(new JScrollPane(textarea3));
    frame.setSize(300, 400);/*from   w  w  w  .  ja  v  a2  s . co m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        @Override/* w  ww  .  java  2s .co m*/
        public void run() {
            JFrame frame = new JFrame("Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            frame.add(new JScrollPane(new MyTextArea()));
            frame.pack();
            frame.setVisible(true);
        }
    });
}