Example usage for javax.swing JScrollPane setViewportView

List of usage examples for javax.swing JScrollPane setViewportView

Introduction

In this page you can find the example usage for javax.swing JScrollPane setViewportView.

Prototype

public void setViewportView(Component view) 

Source Link

Document

Creates a viewport if necessary and then sets its view.

Usage

From source file:AddCheckBoxAction.java

public static void main(String[] args) {
    CheckBoxPanel chD = new CheckBoxPanel();
    JFrame mainFrame = new JFrame();
    JScrollPane scrollP = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollP.setViewportView(chD);
    mainFrame.setSize(320, 200);/*  w  w  w .  ja  v  a 2  s.  c o m*/
    mainFrame.getContentPane().add(scrollP);

    mainFrame.setVisible(true);
}

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);/*from ww  w . j ava  2 s.com*/
    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: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);//w w w.j  a v  a2  s.co  m
    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: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 .  j  ava 2s  . co  m

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

From source file:ComponentTree.java

/**
 * This main() method demonstrates the use of the ComponentTree class: it
 * puts a ComponentTree component in a Frame, and uses the ComponentTree to
 * display its own GUI hierarchy. It also adds a TreeSelectionListener to
 * display additional information about each component as it is selected
 *///w  ww. j a v a 2 s.c o m
public static void main(String[] args) {
    // Create a frame for the demo, and handle window close requests
    JFrame frame = new JFrame("ComponentTree Demo");
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    // Create a scroll pane and a "message line" and add them to the
    // center and bottom of the frame.
    JScrollPane scrollpane = new JScrollPane();
    final JLabel msgline = new JLabel(" ");
    frame.getContentPane().add(scrollpane, BorderLayout.CENTER);
    frame.getContentPane().add(msgline, BorderLayout.SOUTH);

    // Now create the ComponentTree object, specifying the frame as the
    // component whose tree is to be displayed. Also set the tree's font.
    JTree tree = new ComponentTree(frame);
    tree.setFont(new Font("SansSerif", Font.BOLD, 12));

    // Only allow a single item in the tree to be selected at once
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Add an event listener for notifications when
    // the tree selection state changes.
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            // Tree selections are referred to by "path"
            // We only care about the last node in the path
            TreePath path = e.getPath();
            Component c = (Component) path.getLastPathComponent();
            // Now we know what component was selected, so
            // display some information about it in the message line
            if (c.isShowing()) {
                Point p = c.getLocationOnScreen();
                msgline.setText("x: " + p.x + "  y: " + p.y + "  width: " + c.getWidth() + "  height: "
                        + c.getHeight());
            } else {
                msgline.setText("component is not showing");
            }
        }
    });

    // Now that we've set up the tree, add it to the scrollpane
    scrollpane.setViewportView(tree);

    // Finally, set the size of the main window, and pop it up.
    frame.setSize(600, 400);
    frame.setVisible(true);
}

From source file:Main.java

public static JScrollPane createJScrollPane(JComponent component) {
    final JScrollPane scrollPane = new JScrollPane();

    scrollPane.setViewportView(component);

    return scrollPane;
}

From source file:Main.java

/**
 * Creates a new <code>JScrollPane</code> object with the given properties.
 *
 * @param list The list of the scroll pane
 * @return A <code>JScrollPane</code> object
 *//*from  w ww .  j  ava2 s .  c om*/
public static JScrollPane createJScrollPane(JList list) {
    JScrollPane jScrollPane = new JScrollPane();
    jScrollPane.setViewportView(list);
    jScrollPane.setAutoscrolls(true);
    return jScrollPane;
}

From source file:Main.java

static public Component scrollpaneFor(JPanel panel) {
    JScrollPane scrollPanel = new javax.swing.JScrollPane();
    scrollPanel.setName(panel.getName());
    scrollPanel.setViewportView(panel);
    return scrollPanel;
}

From source file:Main.java

/**
 * Creates a new <code>JScrollPane</code> object with the given properties.
 *
 * @param component The component of the scroll pane
 * @param bounds The dimension of the component
 * @param backgroundColor The color of the background
 * @param noBorder if true then the scroll pane is without border otherwise
 * the scroll pane will have also a border
 * @param visible if true then the scroll pane will be visible otherwise the
 * scroll pane will be invisible/*from  w ww . jav  a 2  s  . c  o  m*/
 * @return A <code>JScrollPane</code> object
 */
public static JScrollPane createJScrollPane(Component component, Rectangle bounds, Color backgroundColor,
        boolean noBorder, boolean visible) {
    JScrollPane pane = new JScrollPane();
    if (bounds != null) {
        pane.setBounds(bounds);
    }
    pane.setBackground(backgroundColor);
    pane.setViewportView(component);
    if (noBorder) {
        pane.setBorder(null);
    }
    if (!visible) {
        pane.setVisible(false);
    }
    return pane;
}

From source file:eu.europa.ec.markt.dss.applet.util.ComponentFactory.java

/**
 * /*from   w  w  w  . j  a v  a 2s.co  m*/
 * @param component
 * @return
 */
public static JScrollPane createScrollPane(final Component component) {
    final JScrollPane pane = new JScrollPane();
    pane.setViewportView(component);
    return pane;
}