FileDocCategorySizeDatePackage
ScrollPaneWatermark.javaAPI DocExample3596Mon Jan 09 11:01:58 GMT 2006None

ScrollPaneWatermark

public class ScrollPaneWatermark extends JViewport

Fields Summary
BufferedImage
fgimage
BufferedImage
bgimage
TexturePaint
texture
Constructors Summary
public ScrollPaneWatermark()

        super();
    
Methods Summary
public static java.lang.StringfileToString(java.io.File file)

        FileReader reader = new FileReader( file );
        StringWriter writer = new StringWriter();
        char[] buf = new char[1000];
        while ( true ) {
            int n = reader.read( buf, 0, 1000 );
            if ( n == -1 ) {
                break;
            }
            writer.write( buf, 0, n );
        }
        return writer.toString();
    
public static voidmain(java.lang.String[] args)

        JFrame frame = new JFrame("Blocking Window");
        JTextArea jta = new JTextArea(10,40);
        jta.setForeground(Color.white);
        
        ScrollPaneWatermark viewport = new ScrollPaneWatermark();
        viewport.setView(jta);
        viewport.setOpaque(false);
        
        JScrollPane scroll = new JScrollPane();
        scroll.setViewport(viewport);
 
        Container comp = frame.getContentPane();
        comp.add("Center",scroll);
        
        frame.pack();
        frame.show();
        
        new Thread(new BackgroundLoader(viewport)).start();
    
public voidpaintChildren(java.awt.Graphics g)

        super.paintChildren(g);
        if(fgimage != null) {
        g.drawImage(fgimage, 
            getWidth()-fgimage.getWidth(null), 0,
            null);
        }
    
public voidpaintComponent(java.awt.Graphics g)

        // do the superclass behavior first
        super.paintComponent(g);
        
        // paint the texture
        if(texture != null) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setPaint(texture);
            g.fillRect(0,0,getWidth(),getHeight());
        }
    
public voidsetBackgroundTexture(java.net.URL url)

        bgimage = ImageIO.read(url);
        Rectangle rect = new Rectangle(0,0,
                bgimage.getWidth(null),bgimage.getHeight(null));
        texture = new TexturePaint(bgimage, rect);
    
public voidsetForegroundBadge(java.net.URL url)

        fgimage = ImageIO.read(url);
    
public voidsetView(javax.swing.JComponent view)

        view.setOpaque(false);
        super.setView(view);