Path: blob/master/src/demo/share/jfc/SwingSet2/ScrollPaneDemo.java
41152 views
/*1*2* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7*8* - Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* - Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* - Neither the name of Oracle nor the names of its16* contributors may be used to endorse or promote products derived17* from this software without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS20* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,21* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR22* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR23* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,24* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,25* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR26* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF27* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING28* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233import javax.swing.*;34import javax.swing.event.*;35import javax.swing.text.*;36import javax.swing.border.*;37import javax.swing.colorchooser.*;38import javax.swing.filechooser.*;39import javax.accessibility.*;4041import java.awt.*;42import java.awt.event.*;43import java.beans.*;44import java.util.*;45import java.io.*;46import java.applet.*;47import java.net.*;4849/**50* Scroll Pane Demo51*52* @author Jeff Dinkins53*/54public class ScrollPaneDemo extends DemoModule {5556/**57* main method allows us to run as a standalone demo.58*/59public static void main(String[] args) {60ScrollPaneDemo demo = new ScrollPaneDemo(null);61demo.mainImpl();62}6364/**65* ScrollPaneDemo Constructor66*/67public ScrollPaneDemo(SwingSet2 swingset) {68super(swingset, "ScrollPaneDemo", "toolbar/JScrollPane.gif");6970ImageIcon crayons = createImageIcon("scrollpane/crayons.jpg", getString("ScrollPaneDemo.crayons"));71getDemoPanel().add(new ImageScroller(this, crayons), BorderLayout.CENTER);72}737475/**76* ScrollPane class that demonstrates how to set the various column and row headers77* and corners.78*/79class ImageScroller extends JScrollPane {80public ImageScroller(ScrollPaneDemo demo, Icon icon) {81super();8283// Panel to hold the icon image84JPanel p = new JPanel(new BorderLayout());85p.add(new JLabel(icon), BorderLayout.CENTER);86getViewport().add(p);8788// Create and add a column header to the scrollpane89JLabel colHeader = new JLabel(90demo.createImageIcon("scrollpane/colheader.jpg", getString("ScrollPaneDemo.colheader")));91setColumnHeaderView(colHeader);9293// Create and add a row header to the scrollpane94JLabel rowHeader = new JLabel(95demo.createImageIcon("scrollpane/rowheader.jpg", getString("ScrollPaneDemo.rowheader")));96setRowHeaderView(rowHeader);9798// Create and add the upper left corner99JLabel cornerUL = new JLabel(100demo.createImageIcon("scrollpane/upperleft.jpg", getString("ScrollPaneDemo.upperleft")));101setCorner(UPPER_LEFT_CORNER, cornerUL);102103// Create and add the upper right corner104JLabel cornerUR = new JLabel(105demo.createImageIcon("scrollpane/upperright.jpg", getString("ScrollPaneDemo.upperright")));106setCorner(UPPER_RIGHT_CORNER, cornerUR);107108// Create and add the lower left corner109JLabel cornerLL = new JLabel(110demo.createImageIcon("scrollpane/lowerleft.jpg", getString("ScrollPaneDemo.lowerleft")));111setCorner(LOWER_LEFT_CORNER, cornerLL);112113JScrollBar vsb = getVerticalScrollBar();114JScrollBar hsb = getHorizontalScrollBar();115116vsb.setValue(icon.getIconHeight());117hsb.setValue(icon.getIconWidth()/10);118}119}120121}122123124