java - 设计页面中的 GUI 和 RUN 时的 GUI 不同(Eclipse)

标签 java eclipse jpanel jcomponent

我想通过轻松地将组件拖放到 Eclipse 的设计页面来管理 GUI 中组件的位置。这是我在设计页面中看到的 GUI。(右键单击>测试/预览)

Design page

我认为在设计页面中完成重新排列组件后,当我运行应用程序时它看起来会很相似。但是,这个GUI出现了。 After run

不同的外观让我很难调整组件,例如 DAY 2 的宽度、Meduction 的高度、DOB : 和绿色背景。
请告诉我是否有解决此问题的方法。谢谢。

最佳答案

您可以使用 GridLayout,其中每天是一列,主题(诊断、治疗等)是行。然后,您在每个网格单元格(例如第一天和诊断)中创建一个组合,其中包含当天和主题的按钮。

[编辑] 我建议的实现是:(SWT.BORDER 标记顶级网格的所有单元格)

    GridLayout topLevelLayout = new GridLayout();
    topLevelLayout.numColumns = 4;
    parent.setLayout(topLevelLayout);

    // head row
    Label label = new Label(parent, SWT.BORDER);
    label.setText("Activity");
    label = new Label(parent, SWT.BORDER);
    label.setText("Day 1");
    label = new Label(parent, SWT.BORDER);
    label.setText("Day 2");
    label = new Label(parent, SWT.BORDER);
    label.setText("Day 3");

    // new row - first cell
    label = new Label(parent, SWT.BORDER);
    label.setText("Diagnosis");

    // Day1 & Diagnosis
    GridLayout cellLayout = new GridLayout();
    cellLayout.numColumns = 2;
    Composite composite = new Composite(parent, SWT.BORDER);
    composite.setLayout(cellLayout);
    Button button = new Button(composite, SWT.NONE);
    button.setText("ECG");
    button = new Button(composite, SWT.NONE);
    button.setText("Blood Pressure");
    button = new Button(composite, SWT.NONE);
    button.setText("Vital signs");
    // other subjects of diagnosis at day 1...

    // Day2 & Diagnosis
    composite = new Composite(parent, SWT.BORDER);
    // same layout like for day1 & diagnosis
    composite.setLayout(cellLayout);
    button = new Button(composite, SWT.NONE);
    button.setText("ECG");
    button = new Button(composite, SWT.NONE);
    button.setText("Labs");
    button = new Button(composite, SWT.NONE);
    button.setText("Blood pressure");
    // other subjects of diagnosis at day 2...

    // Day3 & Diagnosis
    composite = new Composite(parent, SWT.BORDER);
    // same layout like for day1 & diagnosis
    composite.setLayout(cellLayout);
    button = new Button(composite, SWT.NONE);
    button.setText("Stress Tests");
    button = new Button(composite, SWT.NONE);
    button.setText("Labs");
    button = new Button(composite, SWT.NONE);
    button.setText("Cardiac rhythm");
    // other subjects of diagnosis at day 1...

    label = new Label(parent, SWT.BORDER);
    label.setText("Treatment");

关于java - 设计页面中的 GUI 和 RUN 时的 GUI 不同(Eclipse),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31438504/

相关文章:

java - thymeleaf 电子邮件模板背景图像未显示

java - 安卓 : How to pause and resume runnable thread?

java - 如何验证具有重复子元素作为 ID 唯一标记的 xml?

java - 安卓开发问题

java - 程序运行时保持 JPanel 中的计时器处于 Activity 状态

java - Swagger注解为响应类添加json示例

java - HTTP 状态 500 – 内部服务器错误(Java、Eclipse、Servlets、Tomcat)

android - 语法错误,插入 "}"完成ClassBody

java - 按下按钮时使其他类框架设置可见(假)

java - 在 PApplet 之上添加 JPanel