我使用GroupLayout
作为主要布局,基线对齐工作正常,直到我添加内部面板。看起来基线没有通过这些面板传播:虽然直接添加到面板GroupLayout
的所有按钮,标签等都与基线正确对齐,但内部面板内的组件却没有。
由于Scala Swing出乎意料地没有GroupPanel
,我使用Andreas Flierl中的那个,但这不应该是重要的,因为我确信这是潜在的摇摆类的问题以及如何调节它们。
import swing._
import eu.flierl.grouppanel.GroupPanel
val f = new Frame {
contents = new GroupPanel {
val but = new Button { text = "button" }
val lb = new Label { text = "label" }
val inner = new FlowPanel {
contents += new Button { text = "ibut" }
contents += new Label { text = "ilab" }
}
theHorizontalLayout is Sequential (but, lb, inner)
theVerticalLayout is Parallel(Baseline)(but, lb, inner)
}
centerOnScreen()
pack()
open()
}
在屏幕截图中注意,内部面板如何与底部对齐而不是基线。此问题与用于子面板的布局管理器无关(可能是另一个组布局)。
答案 0 :(得分:0)
看来,必须覆盖基础对等体的getBaseline
。太糟糕了,在Scala Swing中没有任何钩子(也许是因为它会让它依赖于Java 1.6?)
val f = new Frame {
contents = new GroupPanel {
val but = new Button { text = "button" }
val lb = new Label { text = "label" }
val inner = new FlowPanel {
val b = new Button { text = "ibut" }
override lazy val peer: javax.swing.JPanel =
new javax.swing.JPanel(new java.awt.FlowLayout(1)) with SuperMixin {
override def getBaseline(w: Int, h: Int): Int =
b.peer.getBaseline(w, h) + getInsets().top
}
// vGap = 0
contents += b
contents += new Label { text = "ilab" }
}
theHorizontalLayout is Sequential(but, lb, inner)
theVerticalLayout is Parallel(Baseline)(but, lb, inner)
}
centerOnScreen()
pack()
open()
}