how to fix the order of the buttons in SWT?

拥有回忆 提交于 2020-01-17 06:01:08

问题


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));   

回答1:


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.



来源:https://stackoverflow.com/questions/16443338/how-to-fix-the-order-of-the-buttons-in-swt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!