문제

layout

I was building an UI by using GridLayout/GridData. The layout supposes to have 3 section, one is the headingComposite, one is the leftEditorComposite, one is the rightEditorComposite. But my problem here is, I dont want my leftEditorComposite/rightEditorComposite's width layout be changed by the content. (like the name textbox, if the input get longer, then the leftEdtiorComposite's width will become longer too.) Is there a way to make them as a fix size width? thanks a lot!

    GridLayout layout = new GridLayout(2, false);
    mainComposite.setLayout(layout);

    scrolledComposite.setContent(mainComposite);

    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.horizontalSpan = 2;
    headingComposite = new Composite(mainComposite, SWT.BORDER);
    headingComposite.setBackground(getBackground());
    headingComposite.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    leftEditorComposite = new Composite(mainComposite, SWT.BORDER);
    leftEditorComposite.setBackground(getBackground());
    leftEditorComposite.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    rightEditorComposite = new Composite(mainComposite, SWT.BORDER);
    rightEditorComposite.setBackground(getBackground());
    rightEditorComposite.setLayoutData(data);
도움이 되었습니까?

해결책

If you know the size of each composite, you could provide a widthHint for both your Composite objects.

leftEditorComposite.widthHint = 200;

and

rightEditorComposite.widthHint = 200;

Alternatively, you can read this question, and hopefully you will get your answer: How to align two composites in a parent composite without using widthHint and heightHint

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top