0

enter image description here

I have a very simple class displaying a jTable, where in column1 I have added a combobox

public class Table extends javax.swing.JFrame {

   public Table() {
    initComponents();
    TableColumn name = jTableProva.getColumnModel().getColumn(1);

    JComboBox combo = new JComboBox();
    combo.addItem("Rain");
    combo.addItem("Snow");
    combo.addItem("Sunny");

    name.setCellEditor(new DefaultCellEditor(combo));
}

My questions:

1) I don't know why combos always appears hidden or "behind" cells when run.

2) I would like to add a JColorChooser in column 2. How can I accomplish this using the Netbeans swing component code? I have added a JColorChooser by drag and drop from palette.

Thanks.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Alberto acepsut
  • 1,972
  • 10
  • 41
  • 87
  • 6
    You'll have to do this in code, not with drag-and-drop. Read the tutorials on [How to Use JTables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html) and you'll see how to do this. Pay particular attention to the section on creating custom editors. – Hovercraft Full Of Eels Jan 21 '12 at 15:58
  • Also, as to your first question, can you show an image of the problem (or link to an image if you're not able to show one yet)? – Hovercraft Full Of Eels Jan 21 '12 at 16:37
  • Picture added: as you can see, no combos is visible in column 1, but there is a combobox on each row for column 1 – Alberto acepsut Jan 21 '12 at 16:47
  • 1
    The combo is used as the column's cell *editor* not its *renderer*, so it makes sense that it won't appear unless you are editing the cell -- nor do you want it to appear until then. – Hovercraft Full Of Eels Jan 21 '12 at 16:49

1 Answers1

2

Absent your sscce, it's not clear what the problem might be. You can compare what you're doing with this working example that shows a DefaultCellEditor having a JComboBox. Using a Combo Box as an Editor also shows a JComboBox; Using Other Editors shows a JButton that launches a JColorChooser.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045