Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.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 如何将栅格拆分为两部分_Java_Swt - Fatal编程技术网

Java 如何将栅格拆分为两部分

Java 如何将栅格拆分为两部分,java,swt,Java,Swt,我使用表查看器构建应用程序 我想将屏幕分为两部分:表、消息 消息应为带滚动条的SWT控制器(可能有很多消息) 应该是这样的 -------------------------------- - toolbar of the table - -------------------------------- - - - Table

我使用表查看器构建应用程序

我想将屏幕分为两部分:表、消息

消息应为带滚动条的SWT控制器(可能有很多消息)

应该是这样的

       --------------------------------
       -         toolbar of the table -
       --------------------------------
       -                              -
       -        Table                 -
       -                              -
       --------------------------------
       -        message               -
       --------------------------------
用于消息的最佳SWT控件是什么?(我需要控制信息+滚动条)

如何分割屏幕?我需要使用SashForm吗

    GridLayout dsGridLayout = new GridLayout();
    dsGridLayout .numColumns = 1;
    // set layout
    parent.setLayout(dsGridLayout);
    // toolBar 
    GridData tBGridData = new GridData();
    tB.horizontalAlignment = SWT.FILL;
    tB.grabExcessHorizontalSpace = true;
    // details control grid data
    GridData dGridData = new GridData();
    dGridData.horizontalAlignment = SWT.FILL;
    dGridData.grabExcessHorizontalSpace = true;
    dGridData.verticalAlignment = SWT.FILL;
    dGridData.grabExcessVerticalSpace = true;
    // Details toolBar
    ToolBar toolBar = createToolBarPart(parent); // Create toolBar for the table
    toolBar.setLayoutData(tBarGridData);
    // Separator line
    createSeperatorLabel(parent);
    // Details control
    Table table = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER ) // Create the table viewer
    table.setLayoutData(dGridData);

您可以将此代码作为起点:

private static Shell    shell;

public static void main(final String[] args)
{
    Display display = new Display();
    shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(1, false));

    createToolbar();
    createTablePart();
    createMessagesPart();

    shell.pack();
    shell.open();
    shell.setSize(500, 350);
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}

private static void createToolbar()
{
    ToolBar toolbar = new ToolBar(shell, SWT.FLAT | SWT.BORDER | SWT.HORIZONTAL | SWT.RIGHT);
    toolbar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    String[] labels = new String[] { "A", "B", "C" };
    for (int i = 0; i < 3; i++)
    {
        ToolItem item = new ToolItem(toolbar, SWT.PUSH);
        item.setText(labels[i]);
    }
    toolbar.pack();
}

private static void createTablePart()
{
    Table table = new Table(shell, SWT.BORDER);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    for(int col = 0; col < 3; col++)
    {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Col " + col);
    }

    for(int row = 0; row < 10; row++)
    {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, row + " " + 0);
        item.setText(1, row + " " + 1);
        item.setText(2, row + " " + 2);
    }

    for(TableColumn col : table.getColumns())
        col.pack();
}

private static void createMessagesPart()
{
    Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    GridData data = new GridData(SWT.FILL, SWT.END, true, false);
    data.heightHint = 50;
    text.setLayoutData(data);

    text.setText("First Message\nSecond Message\nThirdMessage\nFourth Message");
}

您可以将此代码作为起点:

private static Shell    shell;

public static void main(final String[] args)
{
    Display display = new Display();
    shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(1, false));

    createToolbar();
    createTablePart();
    createMessagesPart();

    shell.pack();
    shell.open();
    shell.setSize(500, 350);
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}

private static void createToolbar()
{
    ToolBar toolbar = new ToolBar(shell, SWT.FLAT | SWT.BORDER | SWT.HORIZONTAL | SWT.RIGHT);
    toolbar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    String[] labels = new String[] { "A", "B", "C" };
    for (int i = 0; i < 3; i++)
    {
        ToolItem item = new ToolItem(toolbar, SWT.PUSH);
        item.setText(labels[i]);
    }
    toolbar.pack();
}

private static void createTablePart()
{
    Table table = new Table(shell, SWT.BORDER);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    for(int col = 0; col < 3; col++)
    {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Col " + col);
    }

    for(int row = 0; row < 10; row++)
    {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, row + " " + 0);
        item.setText(1, row + " " + 1);
        item.setText(2, row + " " + 2);
    }

    for(TableColumn col : table.getColumns())
        col.pack();
}

private static void createMessagesPart()
{
    Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    GridData data = new GridData(SWT.FILL, SWT.END, true, false);
    data.heightHint = 50;
    text.setLayoutData(data);

    text.setText("First Message\nSecond Message\nThirdMessage\nFourth Message");
}

您可以将此代码作为起点:

private static Shell    shell;

public static void main(final String[] args)
{
    Display display = new Display();
    shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(1, false));

    createToolbar();
    createTablePart();
    createMessagesPart();

    shell.pack();
    shell.open();
    shell.setSize(500, 350);
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}

private static void createToolbar()
{
    ToolBar toolbar = new ToolBar(shell, SWT.FLAT | SWT.BORDER | SWT.HORIZONTAL | SWT.RIGHT);
    toolbar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    String[] labels = new String[] { "A", "B", "C" };
    for (int i = 0; i < 3; i++)
    {
        ToolItem item = new ToolItem(toolbar, SWT.PUSH);
        item.setText(labels[i]);
    }
    toolbar.pack();
}

private static void createTablePart()
{
    Table table = new Table(shell, SWT.BORDER);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    for(int col = 0; col < 3; col++)
    {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Col " + col);
    }

    for(int row = 0; row < 10; row++)
    {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, row + " " + 0);
        item.setText(1, row + " " + 1);
        item.setText(2, row + " " + 2);
    }

    for(TableColumn col : table.getColumns())
        col.pack();
}

private static void createMessagesPart()
{
    Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    GridData data = new GridData(SWT.FILL, SWT.END, true, false);
    data.heightHint = 50;
    text.setLayoutData(data);

    text.setText("First Message\nSecond Message\nThirdMessage\nFourth Message");
}

您可以将此代码作为起点:

private static Shell    shell;

public static void main(final String[] args)
{
    Display display = new Display();
    shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(1, false));

    createToolbar();
    createTablePart();
    createMessagesPart();

    shell.pack();
    shell.open();
    shell.setSize(500, 350);
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}

private static void createToolbar()
{
    ToolBar toolbar = new ToolBar(shell, SWT.FLAT | SWT.BORDER | SWT.HORIZONTAL | SWT.RIGHT);
    toolbar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    String[] labels = new String[] { "A", "B", "C" };
    for (int i = 0; i < 3; i++)
    {
        ToolItem item = new ToolItem(toolbar, SWT.PUSH);
        item.setText(labels[i]);
    }
    toolbar.pack();
}

private static void createTablePart()
{
    Table table = new Table(shell, SWT.BORDER);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    for(int col = 0; col < 3; col++)
    {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Col " + col);
    }

    for(int row = 0; row < 10; row++)
    {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, row + " " + 0);
        item.setText(1, row + " " + 1);
        item.setText(2, row + " " + 2);
    }

    for(TableColumn col : table.getColumns())
        col.pack();
}

private static void createMessagesPart()
{
    Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
    GridData data = new GridData(SWT.FILL, SWT.END, true, false);
    data.heightHint = 50;
    text.setLayoutData(data);

    text.setText("First Message\nSecond Message\nThirdMessage\nFourth Message");
}


您可以创建eclipse视图并在视图中添加表查看器。视图工具栏可以用作表工具栏,也可以使视图不可关闭。对于邮件,我建议使用StyledText控件,以便您可以将样式(字体大小、字体颜色、字体样式等)应用于邮件。

您可以创建eclipse视图并在视图中添加表查看器。视图工具栏可以用作表工具栏,也可以使视图不可关闭。对于邮件,我建议使用StyledText控件,以便您可以将样式(字体大小、字体颜色、字体样式等)应用于邮件。

您可以创建eclipse视图并在视图中添加表查看器。视图工具栏可以用作表工具栏,也可以使视图不可关闭。对于邮件,我建议使用StyledText控件,以便您可以将样式(字体大小、字体颜色、字体样式等)应用于邮件。

您可以创建eclipse视图并在视图中添加表查看器。视图工具栏可以用作表工具栏,也可以使视图不可关闭。对于消息,我建议使用StyledText控件,以便应用样式(字体大小、字体颜色、字体样式等)到消息。

为什么不为消息部分使用
GridData.widthHint
,并使表部分获取剩余空间?您能给我举个例子吗?消息的SWT控制器应该是什么?为什么不为消息部分使用
GridData.widthHint
,并使表部分获取剩余空间空间?你能给我举个例子吗?消息的SWT控制器应该是什么?为什么不在消息部分使用
GridData.widthHint
,并让表部分占据剩余空间?你能给我举个例子吗?消息的SWT控制器应该是什么?为什么不使用
GridData.widthHint
用于消息部分,并使表部分占据剩余空间?您能给我一个示例吗?消息的SWT控制器应该是什么?您能给我一个如何使用sashForm的示例吗?@user1365697更新了我的答案。您能给我一个如何使用sashForm的示例吗?@user1365697更新了我的答案。你能给我一个如何使用sashForm的示例吗?@user1365697更新了我的答案。你能给我一个如何使用sashForm的示例吗?@user1365697更新了我的答案。