jdk

Форк
0
/
ScrollPaneDemo.java 
114 строк · 4.3 Кб
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

33
import javax.swing.Icon;
34
import javax.swing.ImageIcon;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37
import javax.swing.JScrollBar;
38
import javax.swing.JScrollPane;
39

40
import java.awt.BorderLayout;
41

42
/**
43
 * Scroll Pane Demo
44
 *
45
 * @author Jeff Dinkins
46
 */
47
public class ScrollPaneDemo extends DemoModule {
48

49
    /**
50
     * main method allows us to run as a standalone demo.
51
     */
52
    public static void main(String[] args) {
53
        ScrollPaneDemo demo = new ScrollPaneDemo(null);
54
        demo.mainImpl();
55
    }
56

57
    /**
58
     * ScrollPaneDemo Constructor
59
     */
60
    public ScrollPaneDemo(SwingSet2 swingset) {
61
        super(swingset, "ScrollPaneDemo", "toolbar/JScrollPane.gif");
62

63
        ImageIcon crayons = createImageIcon("scrollpane/crayons.jpg",  getString("ScrollPaneDemo.crayons"));
64
        getDemoPanel().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
     */
72
    class ImageScroller extends JScrollPane {
73
        public ImageScroller(ScrollPaneDemo demo, Icon icon) {
74
            super();
75

76
            // Panel to hold the icon image
77
            JPanel p = new JPanel(new BorderLayout());
78
            p.add(new JLabel(icon), BorderLayout.CENTER);
79
            getViewport().add(p);
80

81
            // Create and add a column header to the scrollpane
82
            JLabel colHeader = new JLabel(
83
                demo.createImageIcon("scrollpane/colheader.jpg", getString("ScrollPaneDemo.colheader")));
84
            setColumnHeaderView(colHeader);
85

86
            // Create and add a row header to the scrollpane
87
            JLabel rowHeader = new JLabel(
88
                demo.createImageIcon("scrollpane/rowheader.jpg", getString("ScrollPaneDemo.rowheader")));
89
            setRowHeaderView(rowHeader);
90

91
            // Create and add the upper left corner
92
            JLabel cornerUL = new JLabel(
93
                demo.createImageIcon("scrollpane/upperleft.jpg", getString("ScrollPaneDemo.upperleft")));
94
            setCorner(UPPER_LEFT_CORNER, cornerUL);
95

96
            // Create and add the upper right corner
97
            JLabel cornerUR = new JLabel(
98
                demo.createImageIcon("scrollpane/upperright.jpg", getString("ScrollPaneDemo.upperright")));
99
            setCorner(UPPER_RIGHT_CORNER, cornerUR);
100

101
            // Create and add the lower left corner
102
            JLabel cornerLL = new JLabel(
103
                demo.createImageIcon("scrollpane/lowerleft.jpg", getString("ScrollPaneDemo.lowerleft")));
104
            setCorner(LOWER_LEFT_CORNER, cornerLL);
105

106
            JScrollBar vsb = getVerticalScrollBar();
107
            JScrollBar hsb = getHorizontalScrollBar();
108

109
            vsb.setValue(icon.getIconHeight());
110
            hsb.setValue(icon.getIconWidth()/10);
111
        }
112
    }
113

114
}
115

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.