• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Background image in jscrollpane

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic