如何在Windows上制作相同高度的SWT按钮,文本和标签?
发布时间:2020-12-13 21:25:15 所属栏目:Windows 来源:网络整理
导读:我正在尝试制作用于聊天的GUI,并且我连续放置了三个SWT控件. 不幸的是,我无法为他们找到漂亮的路线. 以下代码 Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(3,false)); Label firstLabel = new Labe
我正在尝试制作用于聊天的GUI,并且我连续放置了三个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,false)); shell.pack(); shell.open(); shell.setSize(400,300); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); 给 即文本字段与按钮一样高,但文本不在其内部垂直居中. 如果以下方式编写文本代码 Text firstText = new Text(shell,false)); 我会得到 最美丽的结果将由 Text firstText = new Text(shell,SWT.BORDER); firstText.setText("hello"); firstText.setLayoutData(new GridData(SWT.FILL,false)); 是的 但是按钮再次比文本略高. UPDATE 人们说他们在非Windows平台上有很好的结果,但问题可能是如何控制SWT控件的填充/边距. 更新2 即使在最好的情况下,文本字段的高度也小于Windows上的按钮,结果与平台有关.
这是一个代码示例,可以让您了解如何解决您的问题:
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(3,false)); Label secondLabel = new Label(shell,SWT.NONE); secondLabel.setText("PROMPT:"); secondLabel.setLayoutData(new GridData(SWT.BEGINNING,true)); Text secondText = new Text(shell,SWT.BORDER | SWT.MULTI | SWT.WRAP); secondText.setText("hello"); secondText.setLayoutData(new GridData(SWT.FILL,true)); Button secondButton = new Button(shell,SWT.PUSH); secondButton.setText("Say"); secondButton.setLayoutData(new GridData(SWT.BEGINNING,true)); shell.pack(); shell.open(); shell.setSize(400,300); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } 看起来像这样: 没有SWT.BORDER: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows命令相当于egrep
- Windows和ctime/st_ctime
- .net – System.Windows.Input.Key枚举中的Equals键没有条目
- windows-server-2003 – 是否可以在Windows Server 2003上运
- 在Windows 7上安装C#Windows服务
- windows – 如何使用Powershell创建Run As Administrator快
- 升级到Windows 10后,批处理文件中的powershell.exe调用无法
- windows-server-2008-r2 – 是否需要启用Windows防火墙才能
- 为什么我在Get-Module的结果中没有列出Microsoft.Powershel
- 如何“安装”自定义Windows驱动程序?