Adding a remove button to a column in a table

前端 未结 4 1594
小蘑菇
小蘑菇 2020-12-03 12:26

Is it possible to add a Remove button to a cell in a table?

I have a table with 5 columns, I would like to add a 6th column. I want the 6th column to have

4条回答
  •  独厮守ぢ
    2020-12-03 13:12

    One important thing to the chosen answer is that you should not create an instance of TableEditor on every update method call it will slow down the performance or even make the application unresposnive.

    @Override
            public void update(ViewerCell cell) {
    
                TableItem item = (TableItem) cell.getItem();
                Button button;
                if(buttons.containsKey(cell.getElement()))
                {
                    button = buttons.get(cell.getElement());
                }
                else
                {
                    button = new Button((Composite) cell.getViewerRow().getControl(),SWT.NONE);
                    button.setText("Remove");
                    buttons.put(cell.getElement(), button);
                    TableEditor editor = new TableEditor(item.getParent());
                    editor.grabHorizontal  = true;
                    editor.grabVertical = true;
                    editor.setEditor(button , item, cell.getColumnIndex());
                    editor.layout();
                }
            }
    

提交回复
热议问题