jdk
1/*
2*
3* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions
7* are met:
8*
9* - Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11*
12* - Redistributions in binary form must reproduce the above copyright
13* notice, this list of conditions and the following disclaimer in the
14* documentation and/or other materials provided with the distribution.
15*
16* - Neither the name of Oracle nor the names of its
17* contributors may be used to endorse or promote products derived
18* from this software without specific prior written permission.
19*
20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*/
32
33import javax.swing.Icon;34import javax.swing.ImageIcon;35import javax.swing.JLabel;36import javax.swing.JPanel;37import javax.swing.JScrollBar;38import javax.swing.JScrollPane;39
40import java.awt.BorderLayout;41
42/**
43* Scroll Pane Demo
44*
45* @author Jeff Dinkins
46*/
47public class ScrollPaneDemo extends DemoModule {48
49/**50* main method allows us to run as a standalone demo.
51*/
52public static void main(String[] args) {53ScrollPaneDemo demo = new ScrollPaneDemo(null);54demo.mainImpl();55}56
57/**58* ScrollPaneDemo Constructor
59*/
60public ScrollPaneDemo(SwingSet2 swingset) {61super(swingset, "ScrollPaneDemo", "toolbar/JScrollPane.gif");62
63ImageIcon crayons = createImageIcon("scrollpane/crayons.jpg", getString("ScrollPaneDemo.crayons"));64getDemoPanel().add(new ImageScroller(this, crayons), BorderLayout.CENTER);65}66
67
68/**69* ScrollPane class that demonstrates how to set the various column and row headers
70* and corners.
71*/
72class ImageScroller extends JScrollPane {73public ImageScroller(ScrollPaneDemo demo, Icon icon) {74super();75
76// Panel to hold the icon image77JPanel p = new JPanel(new BorderLayout());78p.add(new JLabel(icon), BorderLayout.CENTER);79getViewport().add(p);80
81// Create and add a column header to the scrollpane82JLabel colHeader = new JLabel(83demo.createImageIcon("scrollpane/colheader.jpg", getString("ScrollPaneDemo.colheader")));84setColumnHeaderView(colHeader);85
86// Create and add a row header to the scrollpane87JLabel rowHeader = new JLabel(88demo.createImageIcon("scrollpane/rowheader.jpg", getString("ScrollPaneDemo.rowheader")));89setRowHeaderView(rowHeader);90
91// Create and add the upper left corner92JLabel cornerUL = new JLabel(93demo.createImageIcon("scrollpane/upperleft.jpg", getString("ScrollPaneDemo.upperleft")));94setCorner(UPPER_LEFT_CORNER, cornerUL);95
96// Create and add the upper right corner97JLabel cornerUR = new JLabel(98demo.createImageIcon("scrollpane/upperright.jpg", getString("ScrollPaneDemo.upperright")));99setCorner(UPPER_RIGHT_CORNER, cornerUR);100
101// Create and add the lower left corner102JLabel cornerLL = new JLabel(103demo.createImageIcon("scrollpane/lowerleft.jpg", getString("ScrollPaneDemo.lowerleft")));104setCorner(LOWER_LEFT_CORNER, cornerLL);105
106JScrollBar vsb = getVerticalScrollBar();107JScrollBar hsb = getHorizontalScrollBar();108
109vsb.setValue(icon.getIconHeight());110hsb.setValue(icon.getIconWidth()/10);111}112}113
114}
115