0

I can't seem to add a JComboBox to Jtable. I do not know what is wrong with my code. I have tried the example at http://docs.oracle.com/javase/tutorial/uiswing/components/table.html. It just doesn't work. Here is my code.

     JComboBox comboBox = new JComboBox();
     comboBox.addItem("Snowboarding");
     comboBox.addItem("Rowing");
     comboBox.addItem("Chasing toddlers");
     comboBox.addItem("Speed reading");
     comboBox.addItem("Teaching high school");
     comboBox.addItem("None");

     editAddressFrm.getAddressTable().getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox)); 
mKorbel
  • 109,525
  • 20
  • 134
  • 319
unleashed
  • 331
  • 1
  • 5
  • 17
  • Have you looked at [Using a Combo Box as an Editor](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#combobox) **AND** [Some Demo code](http://docs.oracle.com/javase/tutorial/uiswing/examples/components/TableRenderDemoProject/src/components/TableRenderDemo.java) – Smit Jul 30 '13 at 15:36
  • Thanks for your reply.Yes I have look on that code already and it still doesn't work. – unleashed Jul 30 '13 at 15:40
  • 2
    Can you create [SSCCE](http://sscce.org/)? and what is the exact problem your are facing? `It just doesn't work.` could be anything. – Smit Jul 30 '13 at 15:45
  • The Table is showing normally but without a combo box.The problem is with the code that I pasted above. – unleashed Jul 30 '13 at 15:53
  • In the given oracle example, It uses CellRenderer, that means when you click on that cell it will show you combobox, as its made editable. Otherwise it will just look like normal table cell. – Smit Jul 30 '13 at 16:03
  • 1
    should work, nothing special in JXTable in that respect - for help please a SSCCE – kleopatra Jul 30 '13 at 16:04

1 Answers1

2

I have solved the problem I mistakenly disabled cell editing. All I did was to remove the code below:

     @Override
        public boolean isCellEditable(int rowIndex, int colIndex) {
        return false;   //Disallow the editing of any cell
unleashed
  • 331
  • 1
  • 5
  • 17
  • This what happens when you dont show the related code and others left to open for thousand of speculations. +1 for answering your own question and solving the problem. – Smit Jul 30 '13 at 16:18
  • Whenever I post again I will be sure to post my SSCCE :) – unleashed Jul 30 '13 at 16:27