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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:01:18+00:00 2026-06-15T02:01:18+00:00

I have a JTable with two columns: a key name and the value. In

  • 0

I have a JTable with two columns: a key name and the value. In the value columns are multiple data types allowed like this image:

On the left are the keys and on the right the values (a simple "Map")

So in column 1 I might have a boolean in row 1 and a string in row 2. But the method getColumnClass(...) only allows me to set a data type for the complete column.

Is there any way to set column-row specific data types?

Greetings,
mythbu

  • 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-15T02:01:19+00:00Added an answer on June 15, 2026 at 2:01 am

    You cannot have two data types to the same column. But for your case, my suggestion is use rendering.

    1. Read about Editors and Renderers.

    2. Define the column data type as a component class which contains a JPanel.

    3. Render the column. Your Renderer class returns a Panel to the column. It should have a constraint, basing on that you should add components to the Panel and return the Panel.

    This example shows how rendering can be used in these kind of cases.

    class PanelCellRenderer extends JPanel implements TableCellRenderer {
    public Component getTableCellRendererComponent(final JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
           // row number is used as a constraint.
            if(row == 0) {
                this.add( new JTextField("", 20));
            } else if(row == 1) {
                this.add( new JCheckBox());
            } else if(row == 2) {
                this.add( new JButton());
            } else {
                this.add( new JLabel("Row-4"));
            }
            return this;
       }
    }
    

    // Output:

    The first row is a panel with JTextField.
    Similarly 2nd, 3rd rows has JCheckBox and JButton.
    4th row has a JLabel with text.

    Panel Containing Diff Components

    P.S: This is just a try. Even I haven’t done this before. Please correct me if I am wrong.

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

Sidebar

Related Questions

I have created one Jtable.This table consist of two columns name and timestamp. I
I have a jTable with two columns.First column is set as Boolean(for checkbox) and
I have a JTable with two columns and both are JComboBox, for this purpose
I have a simple JTable, there are two columns that matter: quantity and value
In my JTable, I have two editable numeric columns. The editor for both columns
I have a table with two columns: attribute and value! Attribute is an enum.
i have jtable with 2 column then i want to insert value of it
I have a JTable that has two columns ( editable JTable ). When a
I have a simple JFrame with a JList, a JTable and two JButton as
I have a JTable with few columns that are painted as checkboxes. What I

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.