home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / JBuilder8.iso / Solaris / resource / jre / demo / jfc / SwingSet2 / src / ScrollPaneDemo.java < prev    next >
Encoding:
Java Source  |  2002-09-06  |  4.4 KB  |  132 lines

  1. /*
  2.  * Copyright (c) 2002 Sun Microsystems, Inc. All  Rights Reserved.
  3.  * 
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  * 
  8.  * -Redistributions of source code must retain the above copyright
  9.  *  notice, this list of conditions and the following disclaimer.
  10.  * 
  11.  * -Redistribution in binary form must reproduct the above copyright
  12.  *  notice, this list of conditions and the following disclaimer in
  13.  *  the documentation and/or other materials provided with the distribution.
  14.  * 
  15.  * Neither the name of Sun Microsystems, Inc. or the names of contributors
  16.  * may be used to endorse or promote products derived from this software
  17.  * without specific prior written permission.
  18.  * 
  19.  * This software is provided "AS IS," without a warranty of any kind. ALL
  20.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
  21.  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  22.  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
  23.  * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
  24.  * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
  25.  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
  26.  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
  27.  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
  28.  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
  29.  * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  30.  * 
  31.  * You acknowledge that Software is not designed, licensed or intended for
  32.  * use in the design, construction, operation or maintenance of any nuclear
  33.  * facility.
  34.  */
  35.  
  36. /*
  37.  * @(#)ScrollPaneDemo.java    1.5 02/06/13
  38.  */
  39.  
  40.  
  41. import javax.swing.*;
  42. import javax.swing.event.*;
  43. import javax.swing.text.*;
  44. import javax.swing.border.*;
  45. import javax.swing.colorchooser.*;
  46. import javax.swing.filechooser.*;
  47. import javax.accessibility.*;
  48.  
  49. import java.awt.*;
  50. import java.awt.event.*;
  51. import java.beans.*;
  52. import java.util.*;
  53. import java.io.*;
  54. import java.applet.*;
  55. import java.net.*;
  56.  
  57. /**
  58.  * Scroll Pane Demo
  59.  *
  60.  * @version 1.5 06/13/02
  61.  * @author Jeff Dinkins
  62.  */
  63. public class ScrollPaneDemo extends DemoModule {
  64.  
  65.     /**
  66.      * main method allows us to run as a standalone demo.
  67.      */
  68.     public static void main(String[] args) {
  69.     ScrollPaneDemo demo = new ScrollPaneDemo(null);
  70.     demo.mainImpl();
  71.     }
  72.  
  73.     /**
  74.      * ScrollPaneDemo Constructor
  75.      */
  76.     public ScrollPaneDemo(SwingSet2 swingset) {
  77.     super(swingset, "ScrollPaneDemo", "toolbar/JScrollPane.gif");
  78.  
  79.     ImageIcon crayons = createImageIcon("scrollpane/crayons.jpg",  getString("ScrollPaneDemo.crayons"));
  80.     getDemoPanel().add(new ImageScroller(this, crayons), BorderLayout.CENTER);
  81.     }
  82.  
  83.  
  84.     /**
  85.      * ScrollPane class that demonstrates how to set the various column and row headers
  86.      * and corners.
  87.      */
  88.     class ImageScroller extends JScrollPane {
  89.     public ImageScroller(ScrollPaneDemo demo, Icon icon) {
  90.         super();
  91.  
  92.         // Panel to hold the icon image
  93.         JPanel p = new JPanel(new BorderLayout());
  94.         p.add(new JLabel(icon), BorderLayout.CENTER);
  95.         getViewport().add(p);
  96.  
  97.         // Create and add a column header to the scrollpane
  98.         JLabel colHeader = new JLabel(
  99.         demo.createImageIcon("scrollpane/colheader.jpg", getString("ScrollPaneDemo.colheader")));
  100.         setColumnHeaderView(colHeader);
  101.  
  102.         // Create and add a row header to the scrollpane
  103.         JLabel rowHeader = new JLabel(
  104.         demo.createImageIcon("scrollpane/rowheader.jpg", getString("ScrollPaneDemo.rowheader")));
  105.         setRowHeaderView(rowHeader);
  106.  
  107.         // Create and add the upper left corner
  108.         JLabel cornerUL = new JLabel(
  109.         demo.createImageIcon("scrollpane/upperleft.jpg", getString("ScrollPaneDemo.upperleft")));
  110.         setCorner(UPPER_LEFT_CORNER, cornerUL);
  111.  
  112.         // Create and add the upper right corner
  113.         JLabel cornerUR = new JLabel(
  114.         demo.createImageIcon("scrollpane/upperright.jpg", getString("ScrollPaneDemo.upperright")));
  115.         setCorner(UPPER_RIGHT_CORNER, cornerUR);
  116.  
  117.         // Create and add the lower left corner
  118.         JLabel cornerLL = new JLabel(
  119.         demo.createImageIcon("scrollpane/lowerleft.jpg", getString("ScrollPaneDemo.lowerleft")));
  120.         setCorner(LOWER_LEFT_CORNER, cornerLL);
  121.  
  122.         JScrollBar vsb = getVerticalScrollBar();
  123.         JScrollBar hsb = getHorizontalScrollBar();
  124.  
  125.         vsb.setValue(icon.getIconHeight());
  126.         hsb.setValue(icon.getIconWidth()/10);
  127.     }
  128.     }
  129.  
  130. }
  131.  
  132.