简体   繁体   English

关于WindowBuilder SWT java gui构建的一些问题

[英]Some questions about WindowBuilder SWT java gui building

I'm trying to learn WindowBuilder SWT but I'm having problems finding good samples or good tutorials with real explanations about how to do correct GUIs, for example with all the components centered in the middle of the shell.我正在尝试学习 WindowBuilder SWT,但是我在寻找好的示例或好的教程时遇到了问题,其中包含有关如何正确执行 GUI 的真实解释,例如所有组件都集中在外壳的中间。

I can find some super simple tutorials where you can see only the components and the parts of windowbuilder and a hello world alike project.我可以找到一些超级简单的教程,在这些教程中,您只能看到 windowbuilder 的组件和部分以及类似 hello world 的项目。

I only found that you can use a gridlayout and make a label to fill all the width and height and then it's centered, but that is not the behaviour I'm trying to achieve.我只发现您可以使用 gridlayout 并制作一个标签来填充所有宽度和高度,然后将其居中,但这不是我想要实现的行为。

I want that group of components centered on the screen without filling the screen.我希望这组组件以屏幕为中心而不填满屏幕。 I mean that the component must not become bigger when the user maximices the screen.我的意思是当用户最大化屏幕时,组件不能变大。

In Android this is very easy, you only need to put a Layout inside a Layout, and in the parent layout you must simply center it's content.在 Android 中,这很容易,您只需要将 Layout 放在 Layout 中,而在父布局中,您只需将其内容居中即可。 But here I can't find the way to do it.但在这里我找不到办法做到这一点。 Even I can't find the way to put a layout inside a layout.即使我找不到将布局放入布局中的方法。 So I can't understand how to do cool GUIs.所以我无法理解如何做很酷的 GUI。 These are my questions:这些是我的问题:

  1. How can i center a group of components (for example, a login panel) in the center of the shell even when the shell is maximized?即使外壳最大化,我如何才能将一组组件(例如,登录面板)居中放置在外壳的中心?

  2. It is possible to put layouts inside layouts?可以将布局放在布局中吗? if not, then, how can I do complex and nice GUIs?如果没有,那么,我怎样才能做复杂而漂亮的 GUI 呢?

  3. Is there a repository anywhere where I can download sample codes with complex or nice GUIs done with WindowBuilder SWT?是否有任何地方可以下载带有使用 WindowBuilder SWT 完成的复杂或漂亮 GUI 的示例代码的存储库?

This is a simple SWT app that shows centered controls in a shell.这是一个简单的 SWT 应用程序,它在外壳中显示居中控件。 It an inner composite centered in shell.它是一种以壳为中心的内部复合材料。

  public static void main(final String [] args)
  {
    Display.setAppName("Stackoverflow");

    Display display = new Display();

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

    shell.setText("Stack Overflow");

    shell.setSize(1000, 800);

    shell.setLayout(GridLayoutFactory.swtDefaults().create());

    Composite inner = new Composite(shell, SWT.BORDER);
    inner.setLayoutData(GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).create());

    inner.setLayout(GridLayoutFactory.swtDefaults().create());

    Text text = new Text(inner, SWT.LEAD);
    text.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(200, SWT.DEFAULT).create());

    Button button = new Button(inner, SWT.PUSH);
    button.setText("Login");
    button.setLayoutData(GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).create());

    shell.open();

    while (!shell.isDisposed())
     {
       if (!display.readAndDispatch())
         display.sleep();
     }

    display.dispose();
  }

I have used GridDataFactory and GridLayoutFactory rather that GridLayout and GridData because I think they are slightly easier to understand.我使用了GridDataFactoryGridLayoutFactory而不是GridLayoutGridData因为我认为它们更容易理解。

Windowbuilder is a very powerful tool but when you are new to GUI design you should take your time to read the manual. Windowbuilder 是一个非常强大的工具,但是当您不熟悉 GUI 设计时,您应该花时间阅读手册。 Please google for "WindowBuilder User Guide" and you will find the manual.请谷歌搜索“WindowBuilder 用户指南”,您会找到手册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM