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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:34:17+00:00 2026-05-19T10:34:17+00:00

how can i set the combobox selected value to its opposit column. List<TableCellEditor> editors

  • 0

how can i set the combobox selected value to its opposit column.

List<TableCellEditor> editors = new ArrayList<TableCellEditor>(3);

      private DefaultTableModel model;
      JTable table;
      JButton buttonSave;
    public tableee() {
        // Create the editors to be used for each row

        initComponents();
        String[] items1 = { "one", "two", "three" };
        JComboBox comboBox1 = new JComboBox( items1 );
        DefaultCellEditor dce1 = new DefaultCellEditor( comboBox1 );
        editors.add( dce1 );

        String[] items2 = { "one", "two", "three" };
        JComboBox comboBox2 = new JComboBox( items2 );
        DefaultCellEditor dce2 = new DefaultCellEditor( comboBox2 );
        editors.add( dce2 );

        String[] items3 = { "one", "two", "three" };
        JComboBox comboBox3 = new JComboBox( items3 );
        DefaultCellEditor dce3 = new DefaultCellEditor( comboBox3 );
        editors.add( dce3 );

        //  Create the table with default data

        Object[][] data =
        {
            {new String("1"),new String("")}, //enter data-----------------------------
            {new String("2"),new String("")},
            {new String("3"),new String("")},
            {new String("4"),new String("")}

        };
        String[] columnNames = {"Type","Value"};
         model = new DefaultTableModel(data, columnNames);
         table = new JTable(model)
        {
            //  Determine editor to be used by row
            @Override
            public TableCellEditor getCellEditor(int row, int column)
            {
                int modelColumn = convertColumnIndexToModel( column );

                if (modelColumn == 1 && row < 3)
                    return editors.get(row);
                else
                    return super.getCellEditor(row, column);
            }
        };

      // table.setPreferredScrollableViewportSize(new Dimension(40,50));
       JScrollPane scrollPane = new JScrollPane(table);

setLayout(new BorderLayout());
//setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
add(BorderLayout.NORTH, new JLabel("Mon panier", JLabel.CENTER));
add(BorderLayout.CENTER, scrollPane);
JButton buttonAdd = new JButton("Add");
buttonAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
Object obj1 = GetData(table, 1, 2);
System.out.println("Cell value of 2 column and 3 row :" + obj1);
}
private Object GetData(JTable table, int row_index, int col_index) {
                return table.getModel().getValueAt(row_index, col_index);
            }
        });
}
}
  • 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-19T10:34:18+00:00Added an answer on May 19, 2026 at 10:34 am

    You need to use ActionListeners. For example, you can add an ActionListener to each combobox and then change the table when the action is fired:

        JComboBox comboBox1 = new JComboBox(items1);
        comboBox1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                JComboBox cb = (JComboBox)e.getSource();
                String value = (String)cb.getSelectedItem();
                table.setValueAt(value, 0, 0);
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set the selected value of my Font Family combobox, which has
I create a combobox in a class and want to set the selected value
I have a comboBox that has a datatrigger that set its SelectedIndex based on
I'm trying to set seletected value to a pre-loaded combobox using silverlight with MVVM.
Before any item in a ComboBox is selected, its SelectedItem is null and the
How can I get the value from an unbound column in a combo box
I can set the width and height of my canvas by setting the width
I can set the relationship between View Model and view through following DataContext syntax:
You can set the Vim color scheme by issuing :colorscheme SCHEME_NAME but, oddly enough,
I can set the event on the calendar on my device by using this

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.