首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SWT GridLayout自动列计数

SWT GridLayout自动列计数
EN

Stack Overflow用户
提问于 2013-06-07 14:21:43
回答 1查看 394关注 0票数 1

我正在使用一个SWT GridLayout来显示不同的图像,这样一个奇迹-一个网格。现在我的问题是,GridLayout总是有一个固定的列计数,比如说5。有没有办法让GridLayout变得灵活,这样列计数就可以根据父组件的大小增加或减少呢?(例如,当调整窗口大小时)。

我在GridLayoutConstructor或GridData中找不到选项。RowLayout不能满足我的需求

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-07 20:18:02

您可以在运行时更改布局。

当父组件的大小发生更改时,请更改其GridLayoutnumColumns属性并对父组件调用layout(true)

代码语言:javascript
复制
final Shell shell = new Shell();

final GridLayout layout = new GridLayout( 3, true );
shell.setLayout( layout );

shell.addControlListener( new ControlAdapter() {
    @Override
    public void controlResized( ControlEvent event ) {
        int newColumnNumber = 5; // Calculate your new value here.
        layout.numColumns = newColumnNumber;
        shell.layout( true );
    }
} );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16977553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档