aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Background image in jscrollpane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Background image in jscrollpane" Watch "Background image in jscrollpane" New topic
Author

Background image in jscrollpane

Tejo Kumar
Greenhorn

Joined: Aug 09, 2004
Posts: 21
Hi,

Can u plz help me in keeping the background image in jscrollpane.. I have written the following method in myscrollpane:

image is some Imageicon.
public void paint(Graphics g){

if(image!=null){
Rectangle rec=getViewportBorderBounds();
for( int x = 0; x < rec.width; x += image.getIconWidth() )
for( int y = 0; y < rec.height; y += image.getIconHeight() )
g.drawImage( image.getImage(), x, y, null, null );
getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
}

super.paint( g );

}

But I'm not able to get the image.

Thanks in advance,
Tejo Kumar.
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
I don't quite know what you are drawing on to. If you are using just an ImageIcon, you can set this on a panel and put the panel in the JScrollPane.
Tejo Kumar
Greenhorn

Joined: Aug 09, 2004
Posts: 21
Thanks for ur quick reply.
But I am not able to get it. I am able to apply background color to jscrollpane, but not the background image. Can u plz help me.

Thanks in advance,
Tejo Kumar.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
This line

should go in your class constructor; it only needs to be called once.

Since you are tiling your component you shouldn't need the call to super.paint. But if you put it first in your paint method it won't cover your tiled images with the default background.

Also, the viewport must be set to non–opaque — see JScrollPane api notes at top.

Another option is to tile the viewport itself
Tejo Kumar
Greenhorn

Joined: Aug 09, 2004
Posts: 21
Hi,

Thanks for ur inputs. I have got the result. The method 'isOpaque()' is returning 'true' in super class . I have overridden it to return 'false' and the problem is solved. I once again thanks for all ur inputs.

Regards,
Tejo Kumar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Background image in jscrollpane