Watermark JScrollPane : Scrollpane « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing JFC » ScrollpaneScreenshots 
Watermark JScrollPane
 
/*
Swing Hacks Tips and Tools for Killer GUIs
By Joshua Marinacci, Chris Adamson
First Edition June 2005  
Series: Hacks
ISBN: 0-596-00907-0
Pages: 542
website: http://www.oreilly.com/catalog/swinghks/
*/

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JViewport;

public class ScrollPaneWatermark extends JViewport {
  BufferedImage fgimage, bgimage;

  TexturePaint texture;

  public ScrollPaneWatermark() {
    super();
    // setOpaque(false);
  }

  public void setBackgroundTexture(URL urlthrows IOException {
    bgimage = ImageIO.read(url);
    Rectangle rect = new Rectangle(00, bgimage.getWidth(null), bgimage.getHeight(null));
    texture = new TexturePaint(bgimage, rect);
  }

  public void setForegroundBadge(URL urlthrows IOException {
    fgimage = ImageIO.read(url);
  }

  public void paintComponent(Graphics g) {
    // do the superclass behavior first
    super.paintComponent(g);

    // paint the texture
    if (texture != null) {
      Graphics2D g2 = (Graphics2Dg;
      g2.setPaint(texture);
      g.fillRect(00, getWidth(), getHeight());
    }
  }

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

  public void setView(JComponent view) {
    view.setOpaque(false);
    super.setView(view);
  }

  public static void main(String[] argsthrows Exception {
    JFrame frame = new JFrame();

    JTextArea ta = new JTextArea();
    for (int i = 0; i < 1000; i++) {
      ta.append(Integer.toString(i"  ");
    }

    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);
    // ta.setOpaque(false);

    ScrollPaneWatermark watermark = new ScrollPaneWatermark();
    watermark.setBackgroundTexture(new File("background.jpg").toURL());
    watermark.setForegroundBadge(new File("foreground.png").toURL());
    watermark.setView(ta);

    JScrollPane scroll = new JScrollPane();
    scroll.setViewport(watermark);

    frame.getContentPane().add(scroll);
    frame.pack();
    frame.setSize(600600);
    frame.setVisible(true);
  }

}

           
         
  
Related examples in the same category
1. Creating a JScrollPane Container
2. Create a scrollable list
3. Controlling the scrollbars in a JScrollPaneControlling the scrollbars in a JScrollPane
4. JViewport: Move and View JViewport: Move and View
5. ScrollPane Sample
6. Scrollpane rulerScrollpane ruler
7. Customized ScrollPaneCustomized ScrollPane
8. ScrollPane with imageScrollPane with image
9. Scrolling ProgrammaticallyScrolling Programmatically
10. A simple JScrollPane for a JList componentA simple JScrollPane for a JList component
11. JScrollPane with row and column headersJScrollPane with row and column headers
12. A simple JScrollPane demonstrationA simple JScrollPane demonstration
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.