Methods Summary |
---|
public static java.lang.String | fileToString(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 void | main(java.lang.String[] args)
JFrame frame = new JFrame("Scroll Pane Watermark Hack");
JTextArea ta = new JTextArea();
ta.setText(fileToString(new File("alice.txt")));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
//ta.setOpaque(false);
ScrollPaneWatermark watermark = new ScrollPaneWatermark();
watermark.setBackgroundTexture(new File("clouds.jpg").toURL());
watermark.setForegroundBadge(new File("flyingsaucer.png").toURL());
watermark.setView(ta);
JScrollPane scroll = new JScrollPane();
scroll.setViewport(watermark);
frame.getContentPane().add(scroll);
frame.pack();
frame.setSize(600,600);
frame.show();
|
public void | paintChildren(java.awt.Graphics g)
super.paintChildren(g);
if(fgimage != null) {
g.drawImage(fgimage,
getWidth()-fgimage.getWidth(null), 0,
null);
}
|
public void | paintComponent(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 void | setBackgroundTexture(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 void | setForegroundBadge(java.net.URL url)
fgimage = ImageIO.read(url);
|
public void | setView(javax.swing.JComponent view)
view.setOpaque(false);
super.setView(view);
|