Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Background image in jscrollpane  RSS feed

 
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.
 
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.
 
Ranch Hand
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
Boost this thread!