在Mac上使用SWT。我创建了一个统一ToolBar。在此工具栏上有一个缩放小部件和一个标签小部件。标注显示比例的当前值,该值由比例上的SelectionListener更新

在程序启动时,scale小工具的拇指不会移动。标签显示值完全按照预期更改,Scale小部件正确跟踪光标移动并报告更改的值。拇指不动。
关闭Unified工具栏并将其重新打开(使用右上角的小按钮)可使拇指完全正常工作。拇指跟踪光标。
简单的,可编译的,可运行的测试代码复制问题在这里:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.*;
public class scaleTest
{
private static Shell shell;
private static Display display;
private ToolBar UnifiedToolBar;
private Scale scale;
private scaleTest()
{
UnifiedToolBar = shell.getToolBar();
ToolItem containScale = new ToolItem( UnifiedToolBar, SWT.SEPARATOR );
containScale.setWidth( 200 );
scale = new Scale( UnifiedToolBar, SWT.HORIZONTAL );
scale.setMaximum( 72 );
scale.setSelection( 2 );
scale.setMinimum( 6 );
scale.setIncrement( 4 );
scale.setPageIncrement( 4 );
scale.setSize( 180, 24 );
containScale.setControl( scale );
ToolItem containLabel = new ToolItem( UnifiedToolBar, SWT.SEPARATOR );
containLabel.setWidth( 20 );
final Label label = new Label( UnifiedToolBar, SWT.NONE );
label.setText( "32" );
containLabel.setControl( label );
scale.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent selectionEvent )
{
label.setText( String.valueOf( scale.getSelection() ) );
}
} ); // end addSelectionListener
} // end of constructor
public static void main( String[] args )
{
display = Display.getDefault();
shell = new Shell( display );
shell.setText( "scaleTest App" );
shell.setSize( 400, 200 );
shell.setLocation( (display.getClientArea().width / 2) - 200
,(display.getClientArea().height / 2) - 100 );
shell.setLayout( new FormLayout() );
scaleTest testExample = new scaleTest();
shell.open();
while( !shell.isDisposed() )
{
if( !display.readAndDispatch() )
display.sleep();
}
display.dispose();
}
} // end scaleTest class我在shell、工具栏和Scale小部件上尝试了layout()、layout(true,true)、redraw()、paint()、pack(),并尝试了尽可能多的合理组合。一个正常人会认为这是一个不合理的大量组合。
问题1:如何让拇指在启动时正常工作?
后续问题,重要性要小得多:
问题2: Scale小部件似乎忽略了pageIncrement和increment设置。为什么?
任何帮助都将不胜感激。
更新:深夜玩游戏。将Scale小部件移动到shell中--不需要对上面包含的测试代码进行其他更改,小部件就能按预期工作-- thumb马上就能工作。它会看到比例和统一的工具栏在第一眼看起来都不太喜欢对方。
发布于 2012-10-20 23:00:58
问题2
您可以通过向SWT.Selection添加一个Listener来实现对步长值的“捕捉”。在下面的代码中,它将捕捉到5的所有倍数
scale.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
// get the current selection and "round" it to the next 5er step
int scaleValue = scale.getSelection();
scaleValue = (int)(Math.round(scaleValue / 5.0) * 5);
// update the label
label.setText("" + (scaleValue));
label.pack();
// update the scale selection
scale.setSelection(scaleValue);
}
});我真的不能帮你解决问题1..。
https://stackoverflow.com/questions/12988844
复制相似问题