In addition to @Tom Seidel's answer:
You can use org.eclipse.swt.widgets.Spinner
. This allows you to use only numbers. You can specify the minimum and maximum value, and the return value is int
, so there is no need to throw String
.
final Composite composite parent = new Composite(superParent, SWT.NONE); parent.setLayout(new FillLayout()); final Spinner spinner = new Spinner(parent, SWT.BORDER); spinner.setvalues(0, 10, Integer.MAX_VALUE, 0, 1, 10);
The Spinner
value can be obtained by calling:
int selectedValue = spinner.getSelection();
source share