Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:24:13+00:00 2026-06-02T18:24:13+00:00

I need to add an image background behind my JTable, should not scrole down

  • 0

I need to add an image background behind my JTable, should not scrole down while scrolling my JTable. currently i have added a Image behing my JTable. using the paint method.

public void paint(Graphics g) 
            {
                // First draw the background image - tiled
                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);
                // Now let the regular paint code do it's work
                super.paint(g);
            }

problem is that. This JTable is at JScrollPane. and when scrolling the pane. also scrolls down the image. and repeats the image at each scroll.

is there any way to restrict scroll on background only. thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:24:14+00:00Added an answer on June 2, 2026 at 6:24 pm

    Paint the background on the JScrollPane instead. You also need to make both the JTable and the cell renderer transparent by using setOpaque(false). (And use the paintComponent method when overriding).

    The code below produced this screenshot:

    screenshot

    public static void main(String[] args) throws IOException {
        JFrame frame = new JFrame("Test");
    
        final BufferedImage image = ImageIO.read(new URL(
                "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png"));
    
        JTable table = new JTable(16, 3) {{
            setOpaque(false);
            setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {{
                setOpaque(false);
            }});
        }};
    
        frame.add(new JScrollPane(table) {{
                setOpaque(false);
                getViewport().setOpaque(false);
            }
            @Override
            protected void paintComponent(Graphics g) {
                g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
                super.paintComponent(g);
            }
    
        });
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex background image and images, that should be on exact positions
I need to add a background for in css file which is not working
In short, my need is to have a background Image in my java app,
I currently have my background set to top right as: #thedivstatus { background-image: url(imagestatus.gif);
I need to add an image/icon to the last column in the row. And
In One of my application i need to add some image in video. so
I need to know can we add image in TextArea through StyleableTextField htmlText because
I am using the Add-on builder and I need to receive binary data (image).
I need to set the image height everytime I'm using background: url('images/something.jpg')[..]; Fe. HTML:
I need to add the following detail image to each div of a certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.