【问题标题】:Change the component weight dynamically in GridBagLayout在 GridBagLayout 中动态改变组件权重
【发布时间】:2011-06-22 15:44:34
【问题描述】:

假设现在 JPanel 中有一些组件,并且布局是使用 GridBagLayout 排列的。是否可以动态更改组件的重量(weightx 或 weighty)(例如按下按钮后)?谢谢。

【问题讨论】:

    标签: java swing gridbaglayout


    【解决方案1】:

    使用新的 GridBagConstraint 删除和添加组件。打完电话

    panel.revalidate();
    panel.repaint();
    

    使用获取当前约束的方法 public GridBagConstraints getConstraints(Component comp)

    【讨论】:

    • 您应该可以将删除和添加替换为GridBagLayout.setConstraints
    • & Tom:你的两个解决方案都很好。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多