If you create a Slider
(org.eclipse.swt.widgets.Slider) then call getMaximum()
on it, the value is 100. But when you actually try dragging the Slider to its maximum value, it only reaches 90.
I can work round this problem:
sl.setSelection(sl.getMaximum()); // sl.getMaximum() is 100
int actualMax = sl.getSelection(); // should be 100, but is actually 90
But something definitely seems to be wrong, no?
As you know Slider
is nothing but ScrollBar
widget,the maximum value that you set is equal to max_value+thumb_value value.
Try this code:
final Slider slider = new Slider(shell, SWT.NONE);
slider.setMaximum(100);
slider.setMinimum(0);
slider.setThumb(20);
slider.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println( slider.getSelection() +" "+ slider.getThumb());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
I can also observe this behavior on Windows 7 with SWT 3.6.1 and SWT 4.2.1.
A simple but somehow dissatisfying workaround would be to use:
sl.setMaximum(110);
Then the values range from 0
to 100
.
Although the provided answers helped to solve the problem, it still took a while for me to implement it correctly. If you want to make the values 0-100
selectable with your slider, you should do:
// we want to have the values 0-100
slider.setMaximum(100 + slider.getThumb());
// this now returns the selected value, which can be from 0-100
slider.getSelection();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With