File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Jtable background image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable background image" Watch "Jtable background image" New topic

Jtable background image

Jude Fawly
Ranch Hand

Joined: Dec 01, 2004
Posts: 33
hi there,

i am using this code to display a background image in my jtable. it is working, but i dont want the image to be scrolled when using the scroll bar in the jscrollpane. how can i do that?

table = new JTable(){
public boolean isCellEditable(int a, int c)
return false;

public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
Component c = super.prepareRenderer( renderer, row, column);
// We want renderer component to be transparent so background image is visible
if( c instanceof JComponent )
return c;

ImageIcon image = new ImageIcon( "images/handbags.JPG" );

public void paint( Graphics g )
Dimension d = getSize();
for( int x = 0; x < d.width; x += image.getIconWidth() )
for( int y = 0; y < d.height; y += image.getIconHeight() )
g.drawImage( image.getImage(), x, y, null, null );


Teach me to die that so I may<br />Rise glorious at the awful day
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I would suggest associating the background image with the JScrollPane's JViewport.
Since the view port itself doesn't scroll, that takes care of the problem.
Here is some sample code: I like to use a border to draw the image,
and in that way avoid excess subclassing, but your mileage may vary.

There is no emoticon for what I am feeling!
I agree. Here's the link:
subject: Jtable background image
It's not a secret anymore!