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 8348189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:37:06+00:00 2026-06-09T07:37:06+00:00

My aim is to create a JTable, and render the far left column cells

  • 0

My aim is to create a JTable, and render the far left column cells only, with the aim of creating row headers for the table.

All row table examples I have come across online seem convoluted or do not fit my purposes, so I am wondering is there a simple way of creating JTable row headers through rendering the left column cells only?

Below I have code of a simple table with 2 columns and two rows. Is it possible someone could modify this, or explain in simple terms, how I could go about rendering the far left column for row header purposes.

Thank you.

import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.util.*;
public class GUITable extends JFrame{public GUITable(){


init();
  }

  public final void init(){
    String[] columnNames = {"", "Gross Weight"};

  Object[][] data = {
  {"", new Integer(100)},};

  final JTable table = new JTable(data, columnNames);
  table.setPreferredScrollableViewportSize(new Dimension(500, 70));
  table.setFillsViewportHeight(true);

  JScrollPane scrollPane = new JScrollPane(table);
  add(scrollPane);
}

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

public void run() {
try {
  UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
  e.printStackTrace();
}
  GUITable ex = new GUITable();
  ex.setVisible(true);
    }
    });
  }
}
  • 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-09T07:37:07+00:00Added an answer on June 9, 2026 at 7:37 am

    Yes – by using a custom TableCellRenderer, you can modify the way the first column (and first column only) displays.

    Essentially you can use this to set the TableCellRenderer on the first column only:

    table.getColumnModel().getColumn(0).setCellRenderer(new CustomRenderer());
    

    And you can extend the DefaultTableCellRenderer to take care of any special rendering you want to do:

    //Custom Renderer - does the default rendering except if told the row should be a different color
    public static class CustomRenderer extends DefaultTableCellRenderer{
    
        public CustomRenderer(){
            super();
            //Customize the rendering however you want
            setBackground(UIManager.getColor("TableHeader.background"));
        }
    }
    

    To put it all together in your example:

    import javax.swing.*; 
    import javax.swing.table.DefaultTableCellRenderer;
    
    import java.awt.*; 
    public class TestTable extends JFrame{
    
        public TestTable(){ 
            init(); 
        } 
    
        public final void init(){ 
            String[] columnNames = {"", "Gross Weight"}; 
    
            Object[][] data = {{"", new Integer(100)},}; 
    
            final JTable table = new JTable(data, columnNames); 
            // Add Renderer to first column only
            table.getColumnModel().getColumn(0).setCellRenderer(new CustomRenderer());
            table.setPreferredScrollableViewportSize(new Dimension(500, 70)); 
            table.setFillsViewportHeight(true); 
    
            JScrollPane scrollPane = new JScrollPane(table); 
            scrollPane.setPreferredSize(new Dimension(300, 200));
            add(scrollPane); 
        } 
    
        public static void main(String[] args) { 
            SwingUtilities.invokeLater(new Runnable() { 
    
                public void run() { 
                    try { 
                        UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); 
                    } catch (Exception e) { 
                        e.printStackTrace(); 
                    } 
                    TestTable ex = new TestTable();
                    ex.pack();
                    ex.setVisible(true); 
    
                } 
            }); 
        } 
    
        //Custom Renderer - does the default rendering except if told the row should be a different color
        public static class CustomRenderer extends DefaultTableCellRenderer{
    
            public CustomRenderer(){
                super();
                //Customize the rendering however you want
                setBackground(UIManager.getColor("TableHeader.background"));
            }
        }
    
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create grouped table as dynamically. My aim is creating sections as
My aim is to create a map function like this map = function ()
My aim is to create a status bar application which will draw drop down
My aim is to create a navigation menu using jquery. when the user rollover
I'm working on a simple crawler in Python. The aim is to create a
Is it possible to create types like e.g. String(20) in scala? The aim would
What I can do: I aim to create a view where a User Control
My overall aim is to create an editor which I can skin using jQuery
as the title suggests, I'm struggling to understand how to create a new table
I am set to create a file explorer using Java. The aim is to

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.