调整表的列大小以填充所有可用空间 [英] Resize the column of a table to fill all the available space

查看:136
本文介绍了调整表的列大小以填充所有可用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse SWT中有这个表,有5列。我调整窗口大小和整个表的大小,但列不会调整大小以填充所有可用的空间。



是否有一个布局方法我可以使用要使列重新调整大小以填充所有可用空间?我发现一些代码,使得列调整大小时,客户端空间已经调整大小,但这似乎是一个小黑客给我。



使用布局本身一定是一个体面的优雅方式。

解决方案

这可能会派上用场:

  Composite tableComposite = new Composite(parent,SWT.NONE); 
TableViewer xslTable = new TableViewer(tableComposite,SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
xslTable.getTable()。setLinesVisible(true);
xslTable.getTable()。setHeaderVisible(true);
TableViewerColumn stylesheetColumn = new TableViewerColumn(xslTable,SWT.NONE);
stylesheetColumn.getColumn()。setText(COLUMN_NAMES [0]);
stylesheetColumn.getColumn()。setResizable(false);
TableViewerColumn conceptColumn = new TableViewerColumn(xslTable,SWT.NONE);
conceptColumn.getColumn()。setText(COLUMN_NAMES [1]);
conceptColumn.getColumn()。setResizable(false);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComposite.setLayout(tableLayout);

layoutTableColumns();

layoutTableColumns 方法

  / ** 
*调整表列的大小,使概念列打包,样式表列占用其余空间
* /
private void layoutTableColumns()
{
//调整列的大小以适应内容
conceptColumn.getColumn()。pack();
stylesheetColumn.getColumn()。pack();
//使用打包宽度作为最小宽度
int stylesheetWidth = stylesheetColumn.getColumn()。getWidth();
int conceptWidth = conceptColumn.getColumn()。getWidth();
//设置样式表列以填充100%和概念列以适合0%,但是它们的打包宽度最小为
tableLayout.setColumnData(stylesheetColumn.getColumn(),新的ColumnWeightData(100,stylesheetWidth)) ;
tableLayout.setColumnData(conceptColumn.getColumn(),new ColumnWeightData(0,conceptWidth));
}


I have this table in Eclipse SWT, with 5 columns. I resize the window and together with that the whole table but the columns don't get resized to fill all the available space.

Is there a layout method I can use in order to make a column resize itself to fill all the available space? I found some code that makes the columns resize when the client space has been resized but that seems like a small hack to me.

There surely must be a decent elegant way of doing this by using the layout itself.

解决方案

This might come in handy:

Composite tableComposite = new Composite(parent, SWT.NONE);
TableViewer xslTable = new TableViewer(tableComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
xslTable.getTable().setLinesVisible(true);
xslTable.getTable().setHeaderVisible(true);
TableViewerColumn stylesheetColumn = new TableViewerColumn(xslTable, SWT.NONE);
stylesheetColumn.getColumn().setText(COLUMN_NAMES[0]);
stylesheetColumn.getColumn().setResizable(false);
TableViewerColumn conceptColumn = new TableViewerColumn(xslTable, SWT.NONE);
conceptColumn.getColumn().setText(COLUMN_NAMES[1]);
conceptColumn.getColumn().setResizable(false);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComposite.setLayout(tableLayout);

layoutTableColumns();

The layoutTableColumns method

  /**
   * Resize table columns so the concept column is packed and the stylesheet column takes the rest of the space
   */
  private void layoutTableColumns()
  {
    // Resize the columns to fit the contents
    conceptColumn.getColumn().pack();
    stylesheetColumn.getColumn().pack();
    // Use the packed widths as the minimum widths
    int stylesheetWidth = stylesheetColumn.getColumn().getWidth();
    int conceptWidth = conceptColumn.getColumn().getWidth();
    // Set stylesheet column to fill 100% and concept column to fit 0%, but with their packed widths as minimums
    tableLayout.setColumnData(stylesheetColumn.getColumn(), new ColumnWeightData(100, stylesheetWidth));
    tableLayout.setColumnData(conceptColumn.getColumn(), new ColumnWeightData(0, conceptWidth));
  }

这篇关于调整表的列大小以填充所有可用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆