开发者

creating comboboxes inside jtable

My aim is to provide an interface like a matrix, each cell in matrix will have 2 values and user will select best among the two.

So i thought of going for jTable and combo boxes, the problem is in my matrix the value of each cell in a column is different. But the following code that adds the combo box to whole column of the table and if i change the combo box value, it changes for the whole table. How to insert combo boxes into the table such that each one has different values

javax.swing.JComboBox k = new javax.swing.JComboBox();
        k.addItem("1");
        k.addItem("2");
        k.addItem("3");
        k.setEnabled(true);
        k.setVisible(true);
this.jTable1.getColumnMode开发者_StackOverflowl().getColumn(0).setCellEditor(new DefaultCellEditor(k));

I also tried with DefaultTableModel

code is

  DefaultTableModel t =new javax.swing.table.DefaultTableModel();
    t.setColumnCount(10);
    t.setRowCount(10);
    t.setValueAt(k, 0, 0);
 jTable1.setModel(t);

but i get the output in the gui as

javax.swing.JComboBox[,0,0,0x0,invalid,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=0.0,alignmentY=0.0,border=,flags=16777544,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=1]

I tried typecasting "k" as JComboBox and JComponent in setValueAt method, which didn't work

Someone please help


Override the getCellEditor(....) method. For example: How to add unique JComboBoxes to a column in a JTable (Java)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜