Example usage for javax.swing ScrollPaneConstants UPPER_RIGHT_CORNER

List of usage examples for javax.swing ScrollPaneConstants UPPER_RIGHT_CORNER

Introduction

In this page you can find the example usage for javax.swing ScrollPaneConstants UPPER_RIGHT_CORNER.

Prototype

String UPPER_RIGHT_CORNER

To view the source code for javax.swing ScrollPaneConstants UPPER_RIGHT_CORNER.

Click Source Link

Document

Identifies the upper right corner of the viewport.

Usage

From source file:MainClass.java

public static JScrollPane createPagingScrollPaneForTable(JTable jt) {
    JScrollPane jsp = new JScrollPane(jt);
    TableModel tmodel = jt.getModel();
    if (!(tmodel instanceof PagingModel)) {
        return jsp;
    }//from   www . java 2  s  . c  o m

    final PagingModel model = (PagingModel) tmodel;
    final JButton upButton = new JButton("UP");
    upButton.setEnabled(false);
    final JButton downButton = new JButton("DOWN");
    if (model.getPageCount() <= 1) {
        downButton.setEnabled(false);
    }

    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            model.pageUp();

            if (model.getPageOffset() == 0) {
                upButton.setEnabled(false);
            }
            downButton.setEnabled(true);
        }
    });

    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            model.pageDown();
            if (model.getPageOffset() == (model.getPageCount() - 1)) {
                downButton.setEnabled(false);
            }
            upButton.setEnabled(true);
        }
    });

    jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton);
    jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton);

    return jsp;
}

From source file:PagingTester.java

public static JScrollPane createPagingScrollPaneForTable(JTable jt) {
    JScrollPane jsp = new JScrollPane(jt);
    TableModel tmodel = jt.getModel();

    // Don't choke if this is called on a regular table . . .
    if (!(tmodel instanceof PagingModel)) {
        return jsp;
    }//from  ww w .  j a  v a2s. com

    // Okay, go ahead and build the real scrollpane
    final PagingModel model = (PagingModel) tmodel;
    final JButton upButton = new JButton(new ArrowIcon(ArrowIcon.UP));
    upButton.setEnabled(false); // starts off at 0, so can't go up
    final JButton downButton = new JButton(new ArrowIcon(ArrowIcon.DOWN));
    if (model.getPageCount() <= 1) {
        downButton.setEnabled(false); // One page...can't scroll down
    }

    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            model.pageUp();

            // If we hit the top of the data, disable the up button.
            if (model.getPageOffset() == 0) {
                upButton.setEnabled(false);
            }
            downButton.setEnabled(true);
        }
    });

    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            model.pageDown();

            // If we hit the bottom of the data, disable the down button.
            if (model.getPageOffset() == (model.getPageCount() - 1)) {
                downButton.setEnabled(false);
            }
            upButton.setEnabled(true);
        }
    });

    // Turn on the scrollbars; otherwise we won't get our corners.
    jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    // Add in the corners (page up/down).
    jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton);
    jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton);

    return jsp;
}