java - 如何设置 SashForm 子项默认大小

标签 java forms resize widget swt

我有一个 SashForm,目标只是制作一个包含 2 个子项的表单:

  • 一张 table
  • 用于在桌面上执行操作的侧菜单

宽度可以调整,但我想设置一个美观的默认值。

我希望在加载表单时表格比侧面菜单更大,例如 75:25 的比例(当前比例为 50:50,这使得侧面菜单太大)。

我已经尝试了一切方法让 children 改变尺寸,但他们根本不做任何事情。我添加了布局,使用了绝对定位,在每种情况下尝试了许多不同的测试值。我看了一遍又一遍,但没有用。无论我做什么,我似乎都无法影响这个小部件的状态,甚至无法找出问题所在。

    shell.setLayout(new FillLayout()); //stretch the form to fill the window
    sf = new SashForm(shell, SWT.NONE);
    GridLayout gl = new GridLayout(2,false);

    sf.setLayout(gl);

    fillComp = new Composite(sf, SWT.NONE);   //child 1: spreadsheet data
    opComp = new Composite (sf, SWT.BORDER);  //child 2: user operation panel
    opComp.setLayout(new FillLayout());

    GridData gd1 = new GridData(
            2, //test values - could be 200000 and it wouldn't make a difference
            2  //
            );

    GridData gd2 = new GridData(
            1, //test values
            1  //
            );


    //gd1.horizontalSpan = 2;  //blablabla
    //gd2.horizontalSpan = 1;  //all do nothing
    //gd1.minimumWidth = 600;    //tested a variety of variables, setting them
    //gd2.minimumWidth = 200;    //to a variety of values

    fillComp.setLayoutData(gd1);
    opComp.setLayoutData(gd2);

    sf.pack();        //these do nothing
    fillComp.pack();  //
    opComp.pack();    //

我有一个附加到 fillComp 的监听器,在发生事件时,它会激活此:

    try {
        displayTable.setBounds(fillComp.getClientArea());
    } catch (Exception ex) { }

监听器可以被删除,并且不会影响两个小部件的宽度。

我可以发布六个不同的代码块,所有这些代码块甚至都未能对布局进行丝毫改变。我可以更改父级的布局,但这只会使该布局变得更小,但仍然同样不可更改。

如果可以的话,请提供见解。我已阅读所有教程和代码片段,但绝对没有任何东西对这个特定的小部件产生影响。

附注这会产生错误:

sf.setWeights(new int[] { 3, 1 });
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Argument not valid

最佳答案

sf.setWeights() 中 int[] 元素的总和应等于 100, 在您的示例中,它应该是{75, 25}

关于java - 如何设置 SashForm 子项默认大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18342681/

相关文章:

iphone - 浏览器大小 html css

java - 在 DataProvider 中使用 LoadableDetachableModel 有何目的?

java - Apache Ignite Cassandra 驱逐

javascript - Angular Material : Get value out of form

c# - UWP 导航 View : How to resize the width?

drag-and-drop - 使用 kineticjs 调整工具大小的最佳结构设置

java - 从输入文本文件填充二维数组

java - setUncaughtExceptionHandler 在 Maven 项目中不起作用

javascript - 当数据在页面上显示至关重要时,页面会不断刷新

javascript - 在哪里记住 onSelect 所需的值