如何对齐两个复合材料中的不同元素?
How can I align different elements in two composites?
我尝试制作这个小部件:
为此,我为组创建了一个组合(有 1 列),为 id 和密码创建了一个有 2 列(用于标签和文本)的组合
然后,我为具有 3 列的 3 个字段(复选框、标签和文本)创建了一个组合
但是,最后一行与 ID 和密码不对齐,因为我想将 "Retry attemps" 与文本字段垂直对齐:
我的代码是:
Composite sqlComposite = new Composite(parent, SWT.NONE);
sqlComposite.setLayout(new GridLayout(1, false));
sqlComposite .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Group sqlGoup = new Group(sqlComposite, SWT.NONE);
group.setLayout(new GridLayout(1, false));
group.setText("sql connection");
Composite sql2Composite = new Composite(sqlGoup, SWT.NONE);
sql2Composite.setLayout(new GridLayout(2, false));
sql2Composite .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label label = new Label(sql2Composite, SWT.NONE);
label.setText("Id");
Text textBoxID = new Text(sql2Composite, SWT.BORDER);
textBoxID.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Label label = new Label(sql2Composite, SWT.NONE);
label.setText("Password");
Text textBoxPass = new Text(sql2Composite, SWT.BORDER);
textBoxPass.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Composite sqlButtonsComposite = new Composite(sqlGoup, SWT.NONE);
sqlButtonsComposite.setLayout(new GridLayout(3, false));
sqlButtonsComposite.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false));
_encryptCheckButton = new Button(sqlButtonsComposite, SWT.CHECK);
_encryptCheckButton.setText("Encrypt");
_encryptCheckButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
Label labelSpinner = new Label(sqlButtonsComposite , SWT.NONE);
labelSpinner.setText("RetryAttempts");
_retryAttemptsSpinner = new Spinner(sqlButtonsComposite, SWT.BORDER);
_retryAttemptsSpinner.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
_retryAttemptsSpinner.setMinimum(MIN_DELTA_SPINNER);
_retryAttemptsSpinner.setMaximum(MAX_DELTA_SPINNER);
_retryAttemptsSpinner.setSelection(DEFAULT_SPINNER_NUMBER);
_retryAttemptsSpinner.setIncrement(INCREMENT_SPINNER_NUMBER);
所以我的问题是:如何对齐 ID、密码和名为 encrypt 的复选框?
谢谢
使用两个 Composites 无法轻松对齐。因此,使用一个具有 3 列的 Composite 并使文本控件跨越两列:
Composite sql2Composite = new Composite(sqlGoup, SWT.NONE);
// 3 columns
sql2Composite.setLayout(new GridLayout(3, false));
sql2Composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label label = new Label(sql2Composite, SWT.NONE);
label.setText("Id");
Text textBoxID = new Text(sql2Composite, SWT.BORDER);
// Span 2 columns
textBoxID.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
label = new Label(sql2Composite, SWT.NONE);
label.setText("Password");
Text textBoxPass = new Text(sql2Composite, SWT.BORDER);
// Span 2 columns
textBoxPass.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
// No second composite
_encryptCheckButton = new Button(sql2Composite, SWT.CHECK);
_encryptCheckButton.setText("Encrypt");
// Don't grab extra space
_encryptCheckButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
Label labelSpinner = new Label(sql2Composite , SWT.NONE);
labelSpinner.setText("RetryAttempts");
_retryAttemptsSpinner = new Spinner(sql2Composite, SWT.BORDER);
// Don't grab extra space
_retryAttemptsSpinner.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
我在上面添加了需要更改的评论
我尝试制作这个小部件:
为此,我为组创建了一个组合(有 1 列),为 id 和密码创建了一个有 2 列(用于标签和文本)的组合
然后,我为具有 3 列的 3 个字段(复选框、标签和文本)创建了一个组合
但是,最后一行与 ID 和密码不对齐,因为我想将 "Retry attemps" 与文本字段垂直对齐:
我的代码是:
Composite sqlComposite = new Composite(parent, SWT.NONE);
sqlComposite.setLayout(new GridLayout(1, false));
sqlComposite .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Group sqlGoup = new Group(sqlComposite, SWT.NONE);
group.setLayout(new GridLayout(1, false));
group.setText("sql connection");
Composite sql2Composite = new Composite(sqlGoup, SWT.NONE);
sql2Composite.setLayout(new GridLayout(2, false));
sql2Composite .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label label = new Label(sql2Composite, SWT.NONE);
label.setText("Id");
Text textBoxID = new Text(sql2Composite, SWT.BORDER);
textBoxID.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Label label = new Label(sql2Composite, SWT.NONE);
label.setText("Password");
Text textBoxPass = new Text(sql2Composite, SWT.BORDER);
textBoxPass.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Composite sqlButtonsComposite = new Composite(sqlGoup, SWT.NONE);
sqlButtonsComposite.setLayout(new GridLayout(3, false));
sqlButtonsComposite.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false));
_encryptCheckButton = new Button(sqlButtonsComposite, SWT.CHECK);
_encryptCheckButton.setText("Encrypt");
_encryptCheckButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
Label labelSpinner = new Label(sqlButtonsComposite , SWT.NONE);
labelSpinner.setText("RetryAttempts");
_retryAttemptsSpinner = new Spinner(sqlButtonsComposite, SWT.BORDER);
_retryAttemptsSpinner.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
_retryAttemptsSpinner.setMinimum(MIN_DELTA_SPINNER);
_retryAttemptsSpinner.setMaximum(MAX_DELTA_SPINNER);
_retryAttemptsSpinner.setSelection(DEFAULT_SPINNER_NUMBER);
_retryAttemptsSpinner.setIncrement(INCREMENT_SPINNER_NUMBER);
所以我的问题是:如何对齐 ID、密码和名为 encrypt 的复选框?
谢谢
使用两个 Composites 无法轻松对齐。因此,使用一个具有 3 列的 Composite 并使文本控件跨越两列:
Composite sql2Composite = new Composite(sqlGoup, SWT.NONE);
// 3 columns
sql2Composite.setLayout(new GridLayout(3, false));
sql2Composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label label = new Label(sql2Composite, SWT.NONE);
label.setText("Id");
Text textBoxID = new Text(sql2Composite, SWT.BORDER);
// Span 2 columns
textBoxID.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
label = new Label(sql2Composite, SWT.NONE);
label.setText("Password");
Text textBoxPass = new Text(sql2Composite, SWT.BORDER);
// Span 2 columns
textBoxPass.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
// No second composite
_encryptCheckButton = new Button(sql2Composite, SWT.CHECK);
_encryptCheckButton.setText("Encrypt");
// Don't grab extra space
_encryptCheckButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
Label labelSpinner = new Label(sql2Composite , SWT.NONE);
labelSpinner.setText("RetryAttempts");
_retryAttemptsSpinner = new Spinner(sql2Composite, SWT.BORDER);
// Don't grab extra space
_retryAttemptsSpinner.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
我在上面添加了需要更改的评论