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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:47:15+00:00 2026-05-22T21:47:15+00:00

I want to add JComboBox inside a JTable (3,3) on column 1. But in

  • 0

I want to add JComboBox inside a JTable (3,3) on column 1. But in the column 1 , each row will have its own set of ComboBox element.
When I tried to use

table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox_Custom));

Each row is being set to same set of ComboBox Values.
But I want each row ComboBox has different items.

  • 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-22T21:47:16+00:00Added an answer on May 22, 2026 at 9:47 pm

    example on java2s.com looks like as works and correctly, then for example (I harcoded JComboBoxes for quick example, and add/change for todays Swing)

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.UIManager.LookAndFeelInfo;
    import javax.swing.table.*;
    
    public class EachRowEditorExample extends JFrame {
    
        private static final long serialVersionUID = 1L;
    
        public EachRowEditorExample() {
            super("EachRow Editor Example");
            try {
                for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    System.out.println(info.getName());
                    if ("Nimbus".equals(info.getName())) {
                        UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (UnsupportedLookAndFeelException e) {
                // handle exception
            } catch (ClassNotFoundException e) {
                // handle exception
            } catch (InstantiationException e) {
                // handle exception
            } catch (IllegalAccessException e) {
                // handle exception
            }
            DefaultTableModel dm = new DefaultTableModel();
            dm.setDataVector(new Object[][]{{"Name", "MyName"}, {"Gender", "Male"}, {"Color", "Fruit"}}, new Object[]{"Column1", "Column2"});
            JTable table = new JTable(dm);
            table.setRowHeight(20);
            JComboBox comboBox = new JComboBox();
            comboBox.addItem("Male");
            comboBox.addItem("Female");
            comboBox.addComponentListener(new ComponentAdapter() {
    
                @Override
                public void componentShown(ComponentEvent e) {
                    final JComponent c = (JComponent) e.getSource();
                    SwingUtilities.invokeLater(new Runnable() {
    
                        @Override
                        public void run() {
                            c.requestFocus();
                            System.out.println(c);
                            if (c instanceof JComboBox) {
                                System.out.println("a");
                            }
                        }
                    });
                }
            });
    
    
            JComboBox comboBox1 = new JComboBox();
            comboBox1.addItem("Name");
            comboBox1.addItem("MyName");
            comboBox1.addComponentListener(new ComponentAdapter() {
    
                @Override
                public void componentShown(ComponentEvent e) {
                    final JComponent c = (JComponent) e.getSource();
                    SwingUtilities.invokeLater(new Runnable() {
    
                        @Override
                        public void run() {
                            c.requestFocus();
                            System.out.println(c);
                            if (c instanceof JComboBox) {
                                System.out.println("a");
                            }
                        }
                    });
                }
            });
    
            JComboBox comboBox2 = new JComboBox();
            comboBox2.addItem("Banana");
            comboBox2.addItem("Apple");
            comboBox2.addComponentListener(new ComponentAdapter() {
    
                @Override
                public void componentShown(ComponentEvent e) {
                    final JComponent c = (JComponent) e.getSource();
                    SwingUtilities.invokeLater(new Runnable() {
    
                        @Override
                        public void run() {
                            c.requestFocus();
                            System.out.println(c);
                            if (c instanceof JComboBox) {
                                System.out.println("a");
                            }
                        }
                    });
                }
            });
            EachRowEditor rowEditor = new EachRowEditor(table);
            rowEditor.setEditorAt(0, new DefaultCellEditor(comboBox1));
            rowEditor.setEditorAt(1, new DefaultCellEditor(comboBox));
            rowEditor.setEditorAt(2, new DefaultCellEditor(comboBox2));
            table.getColumn("Column2").setCellEditor(rowEditor);
            JScrollPane scroll = new JScrollPane(table);
            getContentPane().add(scroll, BorderLayout.CENTER);
            setPreferredSize(new Dimension(400, 120));
            setLocation(150, 100);
            pack();
            setVisible(true);
        }
    
        public static void main(String[] args) {
            EachRowEditorExample frame = new EachRowEditorExample();
            frame.addWindowListener(new WindowAdapter() {
    
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
        }
    }
    

    just add EachRowEditor Class

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

Sidebar

Related Questions

Actually I want to add a JCombobox in a JTable and fire its action
I have a combobox in a form and a button. I want to add
I want to add a JComboBox in Swing that is simple but I want
I want to add combobox Index from database id. public static void selectCompany(javax.swing.JComboBox cmbCategory
I have list of objects(Artikel.java) and i add them to JComboBox. I want a
I have a MFC Combobox i want to add A-Z drives to my combox
I want add UIGestureRecognizerDelegate to UIWebView,but failed. if [self.view addsubView:webView]; So UIWebView is ok,but
I want add label to every row in tableview at right side of the
I want add my custom sidebar next right column all page. Please check this
I have a website built with ASP.NET (3.5) and want add some level of

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.