【发布时间】:2015-12-24 06:44:09
【问题描述】:
我的 scala swing 应用程序中有一个 BoxPanel 按钮,这对我来说看起来很丑,因为这些按钮的大小都不同。我已将其更改为 GridPanel,但随后它们也垂直填充了面板,我发现它更丑陋。如何让所有按钮填充 BoxPanel 的宽度但保持其首选高度?
我尝试了一种解决方法,如下所示,面板将所有内容设置为最大宽度,但没有效果。
val buttons = new BoxPanel(Orientation.Vertical) {
contents += new Button("Normal Button")
contents += new Button("small")
contents += new Button("Significantly larger button than the rest")
val maxWidth = contents map {
(button: Component) => button.preferredSize
} maxBy { _.width }
contents foreach {
(button: Component) => button.preferredSize = maxWidth
}
}
有没有办法使上述变通办法起作用或不是一种变通办法?
【问题讨论】: