I have a Table with multiple columns. Is it possible to create a radio button in each column entry using Jface?

时间:2016-04-04 18:00:05

标签: java swt jface

I have a Table with multiple columns. Is it possible to create a radio button in each column entry using JFace?

I tried to use TableEditor with this I would only add one radio button to a column not on to all columns. I am pretty new to JFace it would be greatly appreciated if you can guide me further on this.

Example table

2 个答案:

答案 0 :(得分:0)

你不能直接放下单选按钮,你将不得不使用图像。使用ColumnLabelProvider作为列并使用getImage方法。

完成此tutorialThis将帮助您提供原生的外观和控制感。

答案 1 :(得分:0)

您应该为表中的每个列/行添加一个单选按钮,但第0列除外。

for (int i = 0; i < employeeCount; i++)
{
    TableItem item; 
    Button radio; 
    TableEditor editor; 

    item = new TableItem(table, SWT.NO_FOCUS);

    item.setText(0, employees[i]); //Let's assume you have an array of employees' names

    radio = new Button(table, SWT.RADIO);
    //TODO: setup your radiobutton here (text, behavior, etc.)
    editor = new TableEditor(table);
    editor.setEditor(radio, item, 1); //1 is the column index (excellent)
    editor.layout();

    radio = new Button(table, SWT.RADIO);
    //TODO: setup your radiobutton here (text, behavior, etc.)
    editor = new TableEditor(table);
    editor.setEditor(radio, item, 2); //2 is the column index (good)
    editor.layout();

    radio = new Button(table, SWT.RADIO);
    //TODO: setup your radiobutton here (name, text, behavior, etc.)
    editor = new TableEditor(table);
    editor.setEditor(radio, item, 3); //3 is the column index (average)
    editor.layout();

    radio = new Button(table, SWT.RADIO);
    //TODO: setup your radiobutton here (text, behavior, etc.)
    editor = new TableEditor(table);
    editor.setEditor(radio, item, 4); //4 is the column index (poor)
    editor.layout();
}

这应该有效。

相关问题