eclipse中table表格每个列充满剩余空间

时间:2024-10-19 06:52:41

1、在eclipse中新建一个swt-java项目,项目的名称为javatable。

eclipse中table表格每个列充满剩余空间

2、在项目中建立一个shell窗口,类名称为javatable。

eclipse中table表格每个列充满剩余空间

3、打开javatable.java这个文件,选择设计模式。

eclipse中table表格每个列充满剩余空间

4、在窗口中增加gridlayout布局,然后加入table表格,中间加入一些列。

eclipse中table表格每个列充满剩余空间

5、运行项目,发现表格中的列固定不变的,怎么使每个列跟随窗口的大小充满表格呢。

eclipse中table表格每个列充满剩余空间

6、选择table,在属性框内双击resized事件,编写窗口controlResized这个方法.

eclipse中table表格每个列充满剩余空间

7、把表格中的列宽加到一起:Table t=(Table)e.getSource(); int tw=0;艘早祓胂 for(int i=0;i<t.getColumnCount();i++){ tw=tw+t.getColumn(i).getWidth(); }

eclipse中table表格每个列充满剩余空间

8、计算表格的当前宽度,把每个列宽占的百分比分配当前空间。for(int i=0;i<t.getColumnCount();i++){t.getColumn(i像粜杵泳).setWidth((int)((double)t.getColumn(i).getWidth()/tw*(t.getBounds().width-20)));}

eclipse中table表格每个列充满剩余空间

9、运行项目,列宽会跟随table的大小充满表格。

eclipse中table表格每个列充满剩余空间
eclipse中table表格每个列充满剩余空间
© 手抄报圈