Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java/SWT中,如何在窗口底部放置标签_Java_Swt - Fatal编程技术网

在Java/SWT中,如何在窗口底部放置标签

在Java/SWT中,如何在窗口底部放置标签,java,swt,Java,Swt,我正在使用SWT编写一个JavaGUI应用程序,它显示了一个包含数百行的大表。 在窗口的底部,我想有一个固定的标签,显示一些状态信息 我的程序如下所示: public class Test { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.V_SCROLL);

我正在使用SWT编写一个JavaGUI应用程序,它显示了一个包含数百行的大表。 在窗口的底部,我想有一个固定的标签,显示一些状态信息

我的程序如下所示:

public class Test {

public static void main(String[] args) {
    Display display = new Display();

    Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.V_SCROLL);
    FillLayout fillLayout = new FillLayout();
    shell.setLayout(fillLayout);
    // GridLayout gridLayout = new GridLayout();
    // shell.setLayout(gridLayout);    
    final Table table = new Table(shell, SWT.NONE);
    table.setHeaderVisible(true);
    final String header[] = {"Feld 1","Feld 2","Feld 3"};
    table.setLinesVisible(true);
    for (int i = 0; i < 3; i++) {
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setText(header[i]);
      column.setWidth(100);
    }
    for (int i = 0; i < 4; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(new String[] { "a" + i, "b" + i, "c" + i });
    }
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    gridData.verticalSpan = 3;
    table.setLayoutData(gridData);

    Label statusLine = new Label(shell, SWT.NULL);
    statusLine.setText("This shall be the status line");

    gridData = new GridData(GridData.VERTICAL_ALIGN_END);
    gridData.horizontalSpan = 3;
    statusLine.setLayoutData(gridData);
            
    shell.setSize(400,100);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
公共类测试{
公共静态void main(字符串[]args){
显示=新显示();
外壳外壳=新外壳(显示,SWT.Shell|U TRIM | SWT.V|U滚动);
FillLayout FillLayout=新的FillLayout();
shell.setLayout(fillLayout);
//GridLayout=新的GridLayout();
//shell.setLayout(gridLayout);
最终表格=新表格(壳牌,SWT.无);
表.setheadervible(true);
最终字符串头[]={“Feld 1”、“Feld 2”、“Feld 3”};
表.setLinesVisible(真);
对于(int i=0;i<3;i++){
TableColumn column=新的TableColumn(表,SWT.NONE);
setText列(标题[i]);
列。设置宽度(100);
}
对于(int i=0;i<4;i++){
TableItem项目=新的TableItem(表,SWT.NONE);
item.setText(新字符串[]{“a”+i,“b”+i,“c”+i});
}
GridData GridData=新的GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
gridData.verticalSpan=3;
表.setLayoutData(gridData);
标签状态行=新标签(shell,SWT.NULL);
statusLine.setText(“这应该是状态行”);
gridData=新的gridData(gridData.VERTICAL\u ALIGN\u END);
gridData.horizontalSpan=3;
statusLine.setLayoutData(gridData);
外壳尺寸(400100);
shell.open();
而(!shell.isDisposed()){
如果(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

如果使用的是网格布局,则标签位于表格下方,但根据表格大小和窗口大小,标签不可见。如果我放大窗口,标签会出现,但不会停留在窗口底部,而是始终位于桌子的正下方。而且表格不可滚动,也就是说,我看不到我的大表格的底线

如果使用的是FillLayout,则表格是可滚动的,但标签占据了窗口的右半部分


有什么建议吗?我如何将标签强制放在窗口底部,并且仍然可以滚动表格?

使用
GridLayout
可以执行以下操作:

GridLayout gridLayout = new GridLayout();
shell.setLayout(gridLayout);

.... your table code

// To get the table to scroll you have to give a height hint

GridData gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
gridData.heightHint = 100;
table.setLayoutData(gridData);

Label statusLine = new Label(shell, SWT.NULL);
statusLine.setText("This shall be the status line");

// Set the label grid data to grab the remaining space and put the label at the bottom

gridData = new GridData(SWT.FILL, SWT.END, true, true);
statusLine.setLayoutData(gridData);

shell.setSize(400, 200);
或者让桌子抓住多余的垂直空间:

GridData gridData = new GridData(SWT.FILL, SWT.TOP, false, true);
gridData.heightHint = 100;
table.setLayoutData(gridData);

Label statusLine = new Label(shell, SWT.NULL);
statusLine.setText("This shall be the status line");

gridData = new GridData(SWT.FILL, SWT.END, true, false);
statusLine.setLayoutData(gridData);

谢谢你,你的建议对我有用!现在,一个相关的问题出现了:如果我调整我的窗口大小,“状态行”将保持在底部。但是当窗口高度小于高度提示时,状态行消失,当我增加窗口大小时,我的表格和状态行之间会出现一个空白区域。有没有一种方法可以根据窗口的大小来增加和缩小桌子区域?我添加了一个替代方法,让桌子占据多余的空间。对我来说,这使状态行保持可见。当空间变小时,表格应该滚动。在有额外空间时调整表的大小要困难得多,但是可以指定更大的高度提示,以便表在大部分时间占用空间。