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

  • Home
  • SEARCH
  • 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 6174387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:44:42+00:00 2026-05-23T23:44:42+00:00

I have a JTable , and I am trying to insert an image behind

  • 0

I have a JTable, and I am trying to insert an image behind the JTable as a Watermark

tblMainView= new JTable(dtModel){

        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 )
        ((JComponent)c).setOpaque(true);
        return c;
        }
        ImageIcon image = new ImageIcon( "images/watermark.png" );

          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);
        }


        public boolean isCellEditable(int rowIndex, int colIndex) {
          return false;
        }
        public Class getColumnClass(int col){
            if (col == 0)  
            {  
            return Icon.class;  
            }else if(col==7){
                return String.class;
            }
        else
            return String.class;  

        }   
        public boolean getScrollableTracksViewportWidth() {
            if (autoResizeMode != AUTO_RESIZE_OFF) {
                if (getParent() instanceof JViewport) {
                return (((JViewport)getParent()).getWidth() > getPreferredSize().width);
                }
            } 
            return false;
            }

    };

The above is the c
ode of my JTable, but the watermark in not visible; let me add that later I place this JTable in a JScrollPane and JSplitPane.

  • 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-05-23T23:44:43+00:00Added an answer on May 23, 2026 at 11:44 pm

    Two possible solutions, but I don’t know which one. 😀 I think the first approach will have the highest chance of success.

    First approach

    Override your paintComponent(Graphics g) method:

    public void paintComponent(Graphics g)
    {
        //First super
        super.paintComponent(g);
    
        g.drawImage(0, 0, getWidth(), getHeight());
    }
    

    Second approach

    Set your JTable opaque to false: table.setOpaque(false);
    Override your paintComponent(Graphics g) method:

    public void paintComponent(Graphics g)
    {
        //First draw
        g.drawImage(0, 0, getWidth(), getHeight());
    
        super.paintComponent(g);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Swing and have been struggling with the JTable component today. Because
I'm trying to build a new java swing component, I realise that I might
I'm new to Java GUI and trying to work with jTable's in SWING. I
I have a JTable with a custom TableCellRenderer and a custom TableCellEditor . By
I have a JTable that holds several JPanels using a custom renderer/editor. The JPanel
I'm trying to have a JTable edition working like in excel: if I start
I have a JTable with a custom cell renderer. The cell is a JPanel
I'm trying to render an specific row of my jtable (it should have a
In the below image I am trying to achieve the following.I have a table
I have a JTable with a custom TableModel called DataTableModel . I initialized the

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.