49495
|
1 |
/*
|
|
2 |
*
|
|
3 |
* Copyright (c) 2007, 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 |
|
|
33 |
|
|
34 |
import javax.swing.*;
|
|
35 |
import javax.swing.event.*;
|
|
36 |
import javax.swing.text.*;
|
|
37 |
import javax.swing.border.*;
|
|
38 |
import javax.swing.colorchooser.*;
|
|
39 |
import javax.swing.filechooser.*;
|
|
40 |
import javax.accessibility.*;
|
|
41 |
|
|
42 |
import java.awt.*;
|
|
43 |
import java.awt.event.*;
|
|
44 |
import java.beans.*;
|
|
45 |
import java.util.*;
|
|
46 |
import java.io.*;
|
|
47 |
import java.applet.*;
|
|
48 |
import java.net.*;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Scroll Pane Demo
|
|
52 |
*
|
|
53 |
* @author Jeff Dinkins
|
|
54 |
*/
|
|
55 |
public class ScrollPaneDemo extends DemoModule {
|
|
56 |
|
|
57 |
/**
|
|
58 |
* main method allows us to run as a standalone demo.
|
|
59 |
*/
|
|
60 |
public static void main(String[] args) {
|
|
61 |
ScrollPaneDemo demo = new ScrollPaneDemo(null);
|
|
62 |
demo.mainImpl();
|
|
63 |
}
|
|
64 |
|
|
65 |
/**
|
|
66 |
* ScrollPaneDemo Constructor
|
|
67 |
*/
|
|
68 |
public ScrollPaneDemo(SwingSet2 swingset) {
|
|
69 |
super(swingset, "ScrollPaneDemo", "toolbar/JScrollPane.gif");
|
|
70 |
|
|
71 |
ImageIcon crayons = createImageIcon("scrollpane/crayons.jpg", getString("ScrollPaneDemo.crayons"));
|
|
72 |
getDemoPanel().add(new ImageScroller(this, crayons), BorderLayout.CENTER);
|
|
73 |
}
|
|
74 |
|
|
75 |
|
|
76 |
/**
|
|
77 |
* ScrollPane class that demonstrates how to set the various column and row headers
|
|
78 |
* and corners.
|
|
79 |
*/
|
|
80 |
class ImageScroller extends JScrollPane {
|
|
81 |
public ImageScroller(ScrollPaneDemo demo, Icon icon) {
|
|
82 |
super();
|
|
83 |
|
|
84 |
// Panel to hold the icon image
|
|
85 |
JPanel p = new JPanel(new BorderLayout());
|
|
86 |
p.add(new JLabel(icon), BorderLayout.CENTER);
|
|
87 |
getViewport().add(p);
|
|
88 |
|
|
89 |
// Create and add a column header to the scrollpane
|
|
90 |
JLabel colHeader = new JLabel(
|
|
91 |
demo.createImageIcon("scrollpane/colheader.jpg", getString("ScrollPaneDemo.colheader")));
|
|
92 |
setColumnHeaderView(colHeader);
|
|
93 |
|
|
94 |
// Create and add a row header to the scrollpane
|
|
95 |
JLabel rowHeader = new JLabel(
|
|
96 |
demo.createImageIcon("scrollpane/rowheader.jpg", getString("ScrollPaneDemo.rowheader")));
|
|
97 |
setRowHeaderView(rowHeader);
|
|
98 |
|
|
99 |
// Create and add the upper left corner
|
|
100 |
JLabel cornerUL = new JLabel(
|
|
101 |
demo.createImageIcon("scrollpane/upperleft.jpg", getString("ScrollPaneDemo.upperleft")));
|
|
102 |
setCorner(UPPER_LEFT_CORNER, cornerUL);
|
|
103 |
|
|
104 |
// Create and add the upper right corner
|
|
105 |
JLabel cornerUR = new JLabel(
|
|
106 |
demo.createImageIcon("scrollpane/upperright.jpg", getString("ScrollPaneDemo.upperright")));
|
|
107 |
setCorner(UPPER_RIGHT_CORNER, cornerUR);
|
|
108 |
|
|
109 |
// Create and add the lower left corner
|
|
110 |
JLabel cornerLL = new JLabel(
|
|
111 |
demo.createImageIcon("scrollpane/lowerleft.jpg", getString("ScrollPaneDemo.lowerleft")));
|
|
112 |
setCorner(LOWER_LEFT_CORNER, cornerLL);
|
|
113 |
|
|
114 |
JScrollBar vsb = getVerticalScrollBar();
|
|
115 |
JScrollBar hsb = getHorizontalScrollBar();
|
|
116 |
|
|
117 |
vsb.setValue(icon.getIconHeight());
|
|
118 |
hsb.setValue(icon.getIconWidth()/10);
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
}
|