4
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by Ezzaral
Featured Replies
  • 1
    Ezzaral 2,714   6 Years Ago

    Try using this for your cell renderer. You can pass it the combo box that you are using for the cell editor.[CODE] class CheckBoxCellRenderer implements TableCellRenderer { JComboBox combo; public CheckBoxCellRenderer(JComboBox comboBox) { this.combo = new JComboBox(); for (int i=0; i<comboBox.getItemCount(); i++){ combo.addItem(comboBox.getItemAt(i)); } } public Component getTableCellRendererComponent(JTable jtable, Object … Read More

0

Sorry my drawing isnt very good.... It look like figure A , but i want it to look like Figure B from start. Any one who used combobox in table has already experienced it...

Attachments diagram.jpg 12.69 KB
0

@Majestic please check my post http://stackoverflow.com/questions/6261017/how-to-add-different-jcombobox-items-in-a-column-of-a-jtable-in-swing/6261853#6261853 and then really ask the question, sure there are lots of ways how to implements that, anyway basic tutorial show this issue in low lever form http://download.oracle.com/javase/tutorial/uiswing/components/table.html#combobox examples for JTable http://www.java2s.com/Code/Java/Swing-JFC/Table.htm (TableCellRenderer + TableCellEditor)

Edited by mKorbel: n/a

0

mkorbel please check the question.................................. Thank you for your help

0

@Majestics, just joke, its Friday OT day > this quoestion invoked only I want to cleaned up my car <

1

Try using this for your cell renderer. You can pass it the combo box that you are using for the cell editor.

class CheckBoxCellRenderer implements TableCellRenderer {
        JComboBox combo;
        public CheckBoxCellRenderer(JComboBox comboBox) {
            this.combo = new JComboBox();
            for (int i=0; i<comboBox.getItemCount(); i++){
                combo.addItem(comboBox.getItemAt(i));
            }
        }
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            combo.setSelectedItem(value);
            return combo;
        }
    }

On your table column, column.setCellRenderer(new CheckBoxCellRenderer(comboBox));

Edited by Ezzaral: n/a

0

Thanx ezzaral , i m dying to check it , if it work u rock 10000000000000000000000000 times.

0

Yes it worked... thanx alot... but my table has three combo boxes... it worked great for only one other two are not working properly..... any idea?

0

It would really depend on how you created the renders and assigned them to the column. If you did it the same way as the first then I don't see any reason why it would not work fine.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.