KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ScrollPaneDemo


1 /*
2  * @(#)ScrollPaneDemo.java 1.9 05/11/17
3  *
4  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * -Redistribution of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * -Redistribution in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
17  * be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any kind. ALL
21  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
22  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
24  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
25  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
26  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
27  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
28  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
29  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  *
32  * You acknowledge that this software is not designed, licensed or intended
33  * for use in the design, construction, operation or maintenance of any
34  * nuclear facility.
35  */

36
37 /*
38  * @(#)ScrollPaneDemo.java 1.9 05/11/17
39  */

40
41
42 import javax.swing.*;
43 import javax.swing.event.*;
44 import javax.swing.text.*;
45 import javax.swing.border.*;
46 import javax.swing.colorchooser.*;
47 import javax.swing.filechooser.*;
48 import javax.accessibility.*;
49
50 import java.awt.*;
51 import java.awt.event.*;
52 import java.beans.*;
53 import java.util.*;
54 import java.io.*;
55 import java.applet.*;
56 import java.net.*;
57
58 /**
59  * Scroll Pane Demo
60  *
61  * @version 1.9 11/17/05
62  * @author Jeff Dinkins
63  */

64 public class ScrollPaneDemo extends DemoModule {
65
66     /**
67      * main method allows us to run as a standalone demo.
68      */

69     public static void main(String JavaDoc[] args) {
70     ScrollPaneDemo demo = new ScrollPaneDemo(null);
71     demo.mainImpl();
72     }
73
74     /**
75      * ScrollPaneDemo Constructor
76      */

77     public ScrollPaneDemo(SwingSet2 swingset) {
78     super(swingset, "ScrollPaneDemo", "toolbar/JScrollPane.gif");
79
80     ImageIcon crayons = createImageIcon("scrollpane/crayons.jpg", getString("ScrollPaneDemo.crayons"));
81     getDemoPanel().add(new ImageScroller(this, crayons), BorderLayout.CENTER);
82     }
83
84
85     /**
86      * ScrollPane class that demonstrates how to set the various column and row headers
87      * and corners.
88      */

89     class ImageScroller extends JScrollPane {
90     public ImageScroller(ScrollPaneDemo demo, Icon icon) {
91         super();
92
93         // Panel to hold the icon image
94
JPanel p = new JPanel(new BorderLayout());
95         p.add(new JLabel(icon), BorderLayout.CENTER);
96         getViewport().add(p);
97
98         // Create and add a column header to the scrollpane
99
JLabel colHeader = new JLabel(
100         demo.createImageIcon("scrollpane/colheader.jpg", getString("ScrollPaneDemo.colheader")));
101         setColumnHeaderView(colHeader);
102
103         // Create and add a row header to the scrollpane
104
JLabel rowHeader = new JLabel(
105         demo.createImageIcon("scrollpane/rowheader.jpg", getString("ScrollPaneDemo.rowheader")));
106         setRowHeaderView(rowHeader);
107
108         // Create and add the upper left corner
109
JLabel cornerUL = new JLabel(
110         demo.createImageIcon("scrollpane/upperleft.jpg", getString("ScrollPaneDemo.upperleft")));
111         setCorner(UPPER_LEFT_CORNER, cornerUL);
112
113         // Create and add the upper right corner
114
JLabel cornerUR = new JLabel(
115         demo.createImageIcon("scrollpane/upperright.jpg", getString("ScrollPaneDemo.upperright")));
116         setCorner(UPPER_RIGHT_CORNER, cornerUR);
117
118         // Create and add the lower left corner
119
JLabel cornerLL = new JLabel(
120         demo.createImageIcon("scrollpane/lowerleft.jpg", getString("ScrollPaneDemo.lowerleft")));
121         setCorner(LOWER_LEFT_CORNER, cornerLL);
122
123         JScrollBar vsb = getVerticalScrollBar();
124         JScrollBar hsb = getHorizontalScrollBar();
125
126         vsb.setValue(icon.getIconHeight());
127         hsb.setValue(icon.getIconWidth()/10);
128     }
129     }
130
131 }
132
133
Popular Tags