how to fix the order of the buttons in SWT?

2019-09-16 04:29发布

I have scroller with 2 buttons

How i can set that the order of the buttons will be in the same raw and not each control : button scroller and button will be in different row

    fComposite= new Composite(composite, SWT.RIGHT_TO_LEFT);
    GridData layoutData= new GridData(SWT.FILL, SWT.RIGHT_TO_LEFT, true, false);
    fComposite.setLayoutData(layoutData);
    layout= new GridLayout(1, false);
    layout.marginHeight= 0;
    layout.marginWidth= 0;
    layout.horizontalSpacing= 0;
    layout.verticalSpacing= 0;

    fComposite.setLayout(layout);

    Display display = parent.getDisplay();
    Shell shell = parent.getShell(); 
    Button button = new Button(fComposite, SWT.LEFT);
    button.setText("Two"); //$NON-NLS-1$
    button.setImage(display.getSystemImage(ICON_1));    

    final Scale scale = new Scale (fComposite, SWT.BORDER);
    Rectangle clientArea = fComposite.getClientArea ();
    scale.setBounds (clientArea.x, clientArea.y, 200, 64);
    scale.setMaximum (5);
    scale.setPageIncrement (1);
    scale.setSelection(5);

    Button rButton = new Button(fComposite, SWT.RIGHT);
    rButton.setText("Two"); //$NON-NLS-1$
    rButton.setImage(display.getSystemImage(ICON_2));   

标签: java swt
1条回答
Rolldiameter
2楼-- · 2019-09-16 05:16

Did you read the article about SWT layouts that I posted in one of your other questions?

The Display and Shell are the first things to create. After that you can add things to the shell.

Your problem is based on the fact, that you created a GridLayout with just one column. Thus all widgets are below each other.

layout= new GridLayout(1, false);

The first parameter is the number of columns. Set it to 3 for three columns.

Please read the documentation of the layout and the article: Understanding layouts in SWT before asking further questions. It will definitely help you.

查看更多
登录 后发表回答