java swt窗口_java – 如何使窗口能够在SWT中变薄?

为什么以下应用程序不允许我使窗口非常薄?最小宽度允许布置3列图像,同时我希望能够实现单列宽.

如何缩小更多?

package tests;

import org.eclipse.swt.SWT;

import org.eclipse.swt.graphics.Image;

import org.eclipse.swt.layout.FillLayout;

import org.eclipse.swt.layout.RowLayout;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Label;

import org.eclipse.swt.widgets.Shell;

public class TryRowLayout {

public static void main(String[] args) {

RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);

rowLayout.wrap = true;

Display display = new Display();

Shell shell = new Shell(display);

shell.setLayout(new FillLayout());

shell.setMinimumSize(1, 1);

//shell.setLayout(rowLayout);

Composite composite = new Composite(shell, SWT.NONE);

composite.setLayout(rowLayout);

Image image = new Image(display, "images/alt_window_32.gif");

Label label;

for(int i=0; i<100; ++i) {

//label = new Label(shell, SWT.NONE);

label = new Label(composite, SWT.NONE);

label.setImage(image);

}

shell.pack();

shell.open();

while (!shell.isDisposed()) {

if (!display.readAndDispatch())

display.sleep();

}

}

}

解决方法:

原因是Windows需要最小窗口宽度才能添加最小/最大/关闭按钮和窗口标题.

Shell的默认样式是

SWT.SHELL_TRIM = SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE

不幸的是,你甚至无法通过强制Shell只显示关闭按钮来解决这个问题:

Shell shell = new Shell(display, SWT.CLOSE | SWT.RESIZE);

Windows仍将强制执行最小宽度.

最后,如果你仍然需要窗口控件,我担心你无能为力.如果您不需要窗口控件,那么您可以使用

Shell shell = new Shell(display, SWT.RESIZE);

这是示例代码:

public static void main(String[] args)

{

RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);

rowLayout.wrap = true;

Display display = new Display();

Shell shell = new Shell(display, SWT.RESIZE);

shell.setLayout(new FillLayout());

shell.setMinimumSize(1, 1);

// shell.setLayout(rowLayout);

Composite composite = new Composite(shell, SWT.NONE);

composite.setLayout(rowLayout);

Label label;

for (int i = 0; i < 100; ++i)

{

// label = new Label(shell, SWT.NONE);

label = new Label(composite, SWT.NONE);

label.setText("A");

}

shell.pack();

shell.open();

shell.setSize(50, 200);

while (!shell.isDisposed())

{

if (!display.readAndDispatch())

display.sleep();

}

}

这就是它的样子:

标签:java,swt

来源: https://codeday.me/bug/20190831/1772634.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值