I have an org.eclipse.swt.widgets.Table
. I put a org.eclipse.swt.widgets.Button
to the last column.
If it is unchanged, my Button hogs all space available in cell both vertically and horizontally.
I figured out a way how to manipulate the width of the Button (see below). However this approach does not work on heights. I would prefer to reduce the height of the Button by some pixels if possible. Or adding some padding above and below. Or increasing the height of the row and leaving the height of the Button unchanged.
Any help is highly appreciated.
Here is what I have so far:
private void createButtons(Table table) {
int items = tableViewer.getTable().getItems().length;
TableEditor[] editors = new TableEditor[items];
Button[] buttons = new Button[items];
for (int i = 0; i < items; i++) {
Button button = new Button(table, SWT.PUSH);
buttons[i] = button;
button.setText("Details");
button.setSize(100, 10); //(Works perfectly on width, fails on height)
TableEditor editor = new TableEditor(tableViewer.getTable());
editors[i] = editor;
editor.minimumHeight = button.getSize().y;
editor.minimumWidth = button.getSize().x;
editor.setEditor(button, tableViewer.getTable().getItem(i), 3);
}
}
The height of a table item is dictated by its content. Usually the height is chosen so that text and image can be displayed. Unless you implement custom painting, you cannot influence the table item height.
To add a margin around the button, you should put it into a Composite with a suitable layout (e.g. a FillLayout
with marginWith
and/or marginHeight
set accordingly).