下面列出了org.eclipse.swt.widgets.Slider#setLayoutData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createSlider(int style) {
fSlider = new Slider(this, SWT.VERTICAL);
fSlider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
fSlider.setValues(0, 0, SLIDER_MAX, SLIDER_MAX, 1, 1);
fSlider.addSelectionListener(this);
fSlider.addMouseListener(this);
if ((style & SWT.V_SCROLL) == 0) {
fSlider.setVisible(false);
}
}
protected void placeComponents( int style )
{
GridLayout gl = new GridLayout( 1, false );
gl.marginBottom = 0;
gl.marginHeight = 0;
gl.marginLeft = 0;
gl.marginRight = 0;
gl.marginTop = 0;
gl.marginWidth = 0;
this.setLayout( gl );
slider = new Slider( this, style );
GridData gd = new GridData( GridData.FILL_BOTH );
slider.setLayoutData( gd );
}
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("FontAwesome Snippet");
shell.setSize(1000, 600);
shell.setLayout(new GridLayout(2, false));
fScrolledComposite = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
fScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
fScrolledComposite.setAlwaysShowScrollBars(false);
fScrolledComposite.setExpandHorizontal(true);
fScrolledComposite.setExpandVertical(true);
Composite composite = new Composite(fScrolledComposite, SWT.NONE);
fScrolledComposite.setContent(composite);
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
rowLayout.marginTop = 5;
rowLayout.marginRight = 5;
rowLayout.marginLeft = 5;
rowLayout.marginBottom = 5;
rowLayout.pack = false;
composite.setLayout(rowLayout);
buildComposite(composite);
calcMinsize(composite);
shell.layout(true, true);
fFontLabel = new Label(shell, SWT.NONE);
fFontLabel.setText("Font size (22)");
fSlider = new Slider(shell, SWT.NONE);
fSlider.addListener(SWT.MouseUp, e -> {
shell.setRedraw(false);
Arrays.asList(composite.getChildren()).forEach(c -> c.dispose());
fFontSize = fSlider.getSelection();
buildComposite(composite);
fFontLabel.setText("Font size (" + fFontSize + ")");
shell.setRedraw(true);
shell.layout(true, true);
calcMinsize(composite);
});
fSlider.setPageIncrement(1);
fSlider.setMaximum(150);
fSlider.setMinimum(4);
fSlider.setSelection(22);
fSlider.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}