Reputation: 3
How can I display a scale in swt with floating point values?
This is what I have right now
Group groupTime = new Group(shell, SWT.BORDER);
groupTime.setLayout(new GridLayout(1,true));
groupTime.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,false, 1, 1));
new Label(groupTime, SWT.NONE).setText("Speed in seconds:");
Scale scale = new Scale (groupTime, SWT.BORDER);
scale.setMaximum (10);
Label speedLabel = new Label(groupTime, SWT.NONE);
speedLabel.setText("time");
scale.addListener(SWT.Selection, new Listener ()
{
public void handleEvent(Event event)
{
speedLabel.setText(scale.getSelection()+"");
}
});
Thanks
Upvotes: 0
Views: 248
Reputation: 36884
It works on integers internally, so you'll have to make it handle floats yourself. This will give you one decimal space:
Scale scale = new Scale(shell, SWT.BORDER);
scale.setMaximum(10 * 10);
Label speedLabel = new Label(shell, SWT.NONE);
speedLabel.setText("time");
scale.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event event)
{
speedLabel.setText((scale.getSelection() / 10f) + "");
}
});
If you need more decimal spaces, then a Scale
really isn't the right widget for you.
Upvotes: 1