我正在嘗試爲聊天做一個GUI,我將三個SWT控件放在一行中。如何在Windows上製作SWT按鈕,文字和標籤高度相同?
不幸的是,我找不到他們美麗的路線。
以下代碼
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(3, false));
Label firstLabel = new Label(shell, SWT.NONE);
firstLabel.setText("PROMPT:");
firstLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
Text firstText = new Text(shell, SWT.NONE);
firstText.setText("hello");
firstText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Button firstButton = new Button(shell, SWT.PUSH);
firstButton.setText("Say");
firstButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
shell.pack();
shell.open();
shell.setSize(400, 300);
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
給出
即文本字段是作爲按鈕一樣高,但文本不裏面垂直居中。
如果代碼文本以下方式
Text firstText = new Text(shell, SWT.NONE);
firstText.setText("hello");
firstText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
我會得到
最美麗的結果將被
Text firstText = new Text(shell, SWT.BORDER);
firstText.setText("hello");
firstText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
這是
給出但是一個按鈕再次比文字稍高。
UPDATE
人說,他們對非Windows平臺的好成績,但問題可能是如何控制SWT控件的填充/利潤率。
更新2
即使在最好的情況下,文本字段高度較小該按鈕的Windows上,其結果是依賴於平臺的。
您目前使用哪種佈局? – Baz
嘗試將'GridLayout'的'verticalSpacing'和'marginHeight'設置爲'0'。這可能會解決你的身高問題。 – Baz
@巴茲沒有幫助。它真的改變了利潤率,但不是高度 – Dims