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

Source Link

Document

Creates an empty (no viewport view) JScrollPane where both horizontal and vertical scrollbars appear when needed.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    JScrollPane listScrollPane = new JScrollPane();
    String[] stringArray = { "Testing", "This", "Stuff" };
    JList<String> rowList = new JList<>(stringArray);

    rowList.setVisibleRowCount(2);/*  w  w  w .  j ava 2 s. c  om*/
    listScrollPane.setViewportView(rowList);
    panel.setLayout(new BorderLayout());
    panel.add(listScrollPane);
    frame.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel dogLabel = new JLabel("www.java2s.com");
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(dogLabel);
    //    scrollPane.getViewport().setView(dogLabel);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);/*from   w w w.  j  a  v a  2 s.c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JScrollPane sPane = new JScrollPane();
    sPane.setPreferredSize(new Dimension(200, 150));
    JButton button = new JButton(new AbstractAction("Create Table") {
        public void actionPerformed(ActionEvent arg0) {
            DefaultTableModel model = new DefaultTableModel(new Integer[][] { { 1, 2 }, { 3, 4 } },
                    new String[] { "A", "B" });
            JTable table = new JTable(model);
            sPane.getViewport().add(table);
        }/*from   w w  w. ja va 2s  .c om*/
    });
    JPanel panel = new JPanel();
    panel.add(sPane);
    panel.add(button);
    JOptionPane.showMessageDialog(null, panel);

}

From source file:JScrollPaneViewport.java

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

    JLabel label = new JLabel("Label");
    label.setPreferredSize(new Dimension(1000, 1000));
    JScrollPane jScrollPane = new JScrollPane();
    jScrollPane.setViewportView(label);/*from  w  w  w. j  av  a  2s  . c  o  m*/

    frame.add(jScrollPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(10, 11, 212, 500);
    frame.getContentPane().add(scrollPane);

    JTree tree = new JTree(addNodes(new File(".")));
    tree.setRootVisible(false);/*from   w  ww  .  j  av a 2s .  c om*/
    tree.setShowsRootHandles(true);

    tree.setBorder(new LineBorder(new Color(0, 0, 0)));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    scrollPane.setViewportView(tree);

    tree.setCellRenderer(new FileTreeCellRenderer());

    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:ScrollSample.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "JScrollPane Sample" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Icon icon = new ImageIcon("dog.jpg");
    JLabel dogLabel = new JLabel(icon);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(dogLabel);
    //    scrollPane.getViewport().setView(dogLabel);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);/*from  w  ww.  j a  v a2 s. c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.setPreferredSize(new Dimension(800, 600));

    String test[] = { "alpha", "bravo", "charlie", "delta", "echo", "omega", "zeta" };
    JList<String> list = new JList<>(test);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setLayoutOrientation(JList.VERTICAL);
    list.setVisibleRowCount(5);//w w  w .j  a v a 2s . c  om
    list.setBounds(50, 150, 75, 90);

    JScrollPane jScrollPane1 = new JScrollPane();
    jScrollPane1.setViewportView(list);

    panel.add(jScrollPane1);

    JFrame f = new JFrame();
    f.add(panel);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setResizable(false);
    f.setFocusable(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextArea textArea = new JTextArea(5, 30);
    textArea.setOpaque(false);//from ww w  .  j av  a 2s  .c  o  m

    JViewport viewport = new JViewport() {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int w = this.getWidth();
            int h = this.getHeight();
            g.setColor(Color.RED);
            g.fillRect(0, 0, w / 2, h / 2);
        }
    };

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewport(viewport);
    scrollPane.setViewportView(textArea);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.setLocationByPlatform(true);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridLayout(1, 2, 2, 2));

    JTextArea tArea1 = new JTextArea();
    tArea1.setLineWrap(true);//from   w w w  . j  a v  a  2 s .co  m
    JTextArea tArea2 = new JTextArea();
    tArea2.setLineWrap(true);
    tArea1.setText("I got a long long line of text in my JTextArea");
    tArea2.setText("I got a long long line of text in my JTextArea");

    JScrollPane scroller1 = new JScrollPane();
    JScrollPane scroller2 = new JScrollPane();
    scroller1.setViewportView(tArea1);
    scroller2.setViewportView(tArea2);

    contentPane.add(scroller1);
    contentPane.add(scroller2);

    frame.setContentPane(contentPane);
    frame.setSize(100, 100);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:ActionsMenuBar.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("TextAction Usage");
    Container contentPane = frame.getContentPane();
    final JScrollPane scrollPane = new JScrollPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    final JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);/*  ww  w . ja  va 2 s .c  om*/

    ActionListener actionListener = new ActionListener() {
        JTextComponent component;

        public void actionPerformed(ActionEvent actionEvent) {
            // Determine which component selected
            String command = actionEvent.getActionCommand();
            if (command.equals("JTextField")) {
                component = new JTextField();
            } else if (command.equals("JPasswordField")) {
                component = new JPasswordField();
            } else if (command.equals("JTextArea")) {
                component = new JTextArea();
            } else if (command.equals("JTextPane")) {
                component = new JTextPane();
            } else {
                component = new JEditorPane();
            }
            scrollPane.setViewportView(component);
            // Process action list
            Action actions[] = component.getActions();
            menuBar.removeAll();
            menuBar.revalidate();
            JMenu menu = null;
            for (int i = 0, n = actions.length; i < n; i++) {
                if ((i % 10) == 0) {
                    menu = new JMenu("From " + i);
                    menuBar.add(menu);
                }
                menu.add(actions[i]);
            }
            menuBar.revalidate();
        }
    };

    String components[] = { "JTextField", "JPasswordField", "JTextArea", "JTextPane", "JEditorPane" };
    final Container componentsContainer = RadioButtonUtils.createRadioButtonGrouping(components,
            "Pick to List Actions", actionListener);
    contentPane.add(componentsContainer, BorderLayout.WEST);

    frame.setSize(400, 300);
    frame.setVisible(true);
}