【问题标题】:Java SWT library horrible layout in Windows 10Windows 10 中的 Java SWT 库可怕的布局
【发布时间】:2016-07-24 05:45:29
【问题描述】:

我使用用于 GUI 的 SWT 库开发了一个桌面应用程序。 在 Windows 7 上运行应用程序运行良好,布局干净。 我试图在 Windows 10 上运行相同的应用程序,这是一场灾难! 巨大的字体和切开的窗户,太可怕了!

我禁用了显示缩放并将 100% 放在视图选项中,但没有,问题仍然存在。 我该如何解决这个问题?

感谢那些愿意帮助我的人。

java,
Snippet:

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.wb.swt.SWTResourceManager;

public class mySWTApp extends Shell {
	private Text txt_name;
	private Text txt_surname;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			mySWTApp shell = new mySWTApp(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * @param display
	 */
	public mySWTApp(Display display) {
		super(display, SWT.SHELL_TRIM);
		setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
		setBackgroundMode(SWT.INHERIT_DEFAULT);
		setLayout(new GridLayout(1, false));
		
		Composite composite = new Composite(this, SWT.BORDER);
		composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
		composite.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
		composite.setLayout(new GridLayout(2, false));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel.setText("Name");
		
		txt_name = new Text(composite, SWT.BORDER);
		txt_name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_1 = new Label(composite, SWT.NONE);
		lblNewLabel_1.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
		lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_1.setText("Surname");
		
		txt_surname = new Text(composite, SWT.BORDER);
		txt_surname.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button btn_add = new Button(composite, SWT.NONE);
		btn_add.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
		GridData gd_btn_add = new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1);
		gd_btn_add.widthHint = 126;
		btn_add.setLayoutData(gd_btn_add);
		btn_add.setText("Insert");
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("Basic Name");
		setSize(450, 135);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}

【问题讨论】:

  • 能否提供eclipse版本。还有一个代码 sn-p?
  • 问题可能是由于您在 Win 8 中的设置造成的吗?
  • 日食火星 .2。 SWT 4.5 稳定版。 Windowsbuilder 最新版本。
  • 添加了片段。再次感谢。
  • 我已经使用 eclipse neon 和 SWT 4.6 更新了我的应用程序,但结果是一样的 :(

标签: java windows user-interface swt windowbuilder


【解决方案1】:

我最近遇到了这个问题,并认为它与Windows 10有关。一些研究表明,真正的原因是Windows 10附带的新PC的分辨率更高!有一个非常简单的解决方案描述在 Perfectmobile community: Solution for eclipse with high resolution laptops。 我按照描述做了,确保更改下载的清单文件的名称以匹配我的应用程序的名称,它工作得很好! 有用的信息也可以在这个Slideshow about scaling SWT on high-resolution screens 中找到,了解如何使您的应用程序具有 dpiAware

【讨论】:

  • Perfectmobile 社区:高分辨率笔记本电脑的 Eclipse 解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-24
  • 1970-01-01
相关资源
最近更新 更多