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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:58:01+00:00 2026-05-24T15:58:01+00:00

I’m new to Swing and have been struggling with the JTable component today. Because

  • 0

I’m new to Swing and have been struggling with the JTable component today. Because I’m trying to make a somewhat-fancy table I haven’t been able to find the particular answers I’m looking for anywhere yet.

I would like to have a “group” of headers at the very top of the table. This means 3 or 4 rows that span the whole table, and “group” the various columns, essentially partitioning them.

Example (pardon the eye strain):

////////////////////////////////ANIMALS//////////////////////////
/////////Mammals///////////////////////Rodents///////////////////
////People/////Dogs//////////Rats/////Rodents of Unusual Size////

Where slashes (“/”) denote whitespace. The first header, titled “ANIMALS” refers to all the columns in the table. The second header down partitions ANIMALS, so on and so forth. After the third and final header we arrive the actual table, where each row will have 4 columns, one for each type of Animal.

Obviously this is an example, and probably a bad one, but this is what I mean by “partitioning headers”.

My question:
I don’t see how JTableHeader and TableColumnModel support this functionality. If they do, can someone nudge me in the right direction. If they don’t, this surely can’t be the first time a Swing app has needed something like this. Any 3rd party components anyone knows of?

Also, I’d like to be able to have “Spacer” or Spanning Rows sprinkled throughout my table, representing a group of rows. These Spacers would exist inside the table (not on top of it like a header), but would span every column and have a single label, representing the name of the group represented by the subsequent rows. Again, I don’t see Swing supporting this, any ideas?

Thanks and I do apologize for the truly-awful example/drawing.

  • 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-24T15:58:01+00:00Added an answer on May 24, 2026 at 3:58 pm

    By default there is only one row of header in a JTable (and it’s not properly a row of the JTable it’s a JTableHeader). Anyway you can implement a TableCellRenderer that display the first n non-header-rows in a fashion like it seems to be header.

    The steps are more ore less the following :

    1. Implement TableCellRenderer to display ordinar JTable’s cell of desired row like header’s cell

    like:

    public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column){   
    
        this.setOpaque(true);
        TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
        return renderer.getTableCellRendererComponent(table, value, isSelected,
              hasFocus, row, column);
    }
    
    1. Extend JTable and implement the following method in order to return the desidered cell renderer:

      public TableCellRenderer getCellRenderer(int row, int column){}
      

    Anyway with your requirements there is another problem to solve: a JTable has a fixed number of column, so you have to find a workaround to achive that result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.