如何在Windows上制作相同高度的SWT按钮,文本和标签?
发布时间:2020-07-24 01:18:43 所属栏目:Windows 来源:互联网
导读:我正在尝试制作用于聊天的GUI,并且我连续放置了三个SWT控件. 不幸的是,我无法为他们找到漂亮的路线. 以下代码 Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(3, false)); Label firstLabel =
我正在尝试制作用于聊天的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下的2017 最新版 MyEclipse启动出现:a java runtim
- Windows C线程参数传递
- .net – System.Windows.Forms.WebBrowser:强制X86?
- Create AD Users by Powershell
- Qt for Windows:Qt 5.11.0 MinGW 静态编译版本(包含OpenS
- 本地windows上安装protobuf和thrit环境
- Vulkan Tutorial 07 Window surface
- Windows 8应用程序是否运行符合标准的JavaScript,HTML5和CS
- Windows Phone 7 – 如何在WIndows Phone应用程序中访问Nav
- glib:windows下基于MSYS2环境编译glib2的过程
推荐文章
站长推荐
热点阅读