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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:31:58+00:00 2026-06-10T19:31:58+00:00

I would like to make one cell in JTable to be a JComboBox object

  • 0

I would like to make one cell in JTable to be a JComboBox object and be able to use it. It must be only one cell, not whole column. The table can contain the specific cell but not always, its placement is not static. My problem lies in putting JComboBox in JTable which can be used. I attached a code I was able to do so far. Table contains the JComboBox but when I click it there is no list and turns cell’s editor on. I would like to make list show up. What should I do or what should be added/modified in code to gain my goal?

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;

public class CustomCellRenderer {
    JTable table;
    TableColumn tcol;

    public static void main(String[] args) {
        new CustomCellRenderer();
    }

    public CustomCellRenderer() {
        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        Object data[][] = { { "Vinod", "Computer", "3" },
                { "Rahul", "History", "2" }, { "Manoj", "Biology", "4" },
                { "Sanjay", "PSD", "5" } };
        String col[] = { "Name", "Course", "Year" };
        DefaultTableModel model = new DefaultTableModel(data, col);
        table = new JTable(model);
        tcol = table.getColumnModel().getColumn(0);
        tcol.setCellRenderer(new CustomTableCellRenderer());
        tcol = table.getColumnModel().getColumn(1);
        tcol.setCellRenderer(new CustomTableCellRenderer());
        tcol = table.getColumnModel().getColumn(2);
        tcol.setCellRenderer(new CustomTableCellRenderer());
        JTableHeader header = table.getTableHeader();
        JScrollPane pane = new JScrollPane(table);
        panel.add(pane);
        frame.add(panel);
        frame.setSize(500, 150);
        frame.setUndecorated(true);
        frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    public class CustomTableCellRenderer extends DefaultTableCellRenderer implements ActionListener {
        public Component getTableCellRendererComponent(JTable table,
                Object obj, boolean isSelected, boolean hasFocus, int row,
                int column) {
            Component cell = super.getTableCellRendererComponent(table, obj,
                    isSelected, hasFocus, row, column);

            if (((String) obj).equals("History")) {
                JComboBox comboBox = new JComboBox();
                comboBox.addItem("History");
                comboBox.addItem("English");
                comboBox.addItem("Biology");
                comboBox.addItem("PE");
                comboBox.addItem("None of the above");
                comboBox.addActionListener(this);

                return comboBox;
            }
            return cell;
        }

        public void actionPerformed(ActionEvent e) {
            System.out.println("Perform some action");
        }
    }
}
  • 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-10T19:31:59+00:00Added an answer on June 10, 2026 at 7:31 pm

    You have to implement a TableCellEditor not a TableCellRenderer and set it with JTable.setCellEditor(TableCellEditor).

    Look at this example.

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

Sidebar

Related Questions

I would like to make one of the div's hidden while rendring. After page
I have two LINQ statements that I would like to make into one, but
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make a UITableViewCell with one label and two accessory types:
I'm playing around with Sinatra, and I would like to make one of my
I would like make a script using PHP (probably need JS) to send POST
I would like make an extension method for the generic class A which takes
I would like to make sure my classes are robust - even if they
I would like to make a password and username entry field. And a submit
I would like to make a JSF inputText field into upper case when 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.