【问题标题】:SWT GridLayout automatic column countSWT GridLayout 自动列数
【发布时间】:2013-06-07 20:18:02
【问题描述】:

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

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

【问题讨论】:

  • 你不能在resize监听器中使用setColumns()setRows()吗?

标签: java eclipse swt


【解决方案1】:

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

当你的父组件大小改变时,改变它的GridLayoutnumColumns属性,并在父组件上调用layout(true)

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 );
    }
} );

【讨论】:

  • 我会试试看是否有帮助
  • 这不是我的问题的确切解决方案,但它帮助我找到了正确的方向 - 谢谢
猜你喜欢
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多