Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Background image in jscrollpane

 
Tejo Kumar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic