我想制作几个面板的窗口.我可以将一个附加到MainFrame的内容:import swing._
class View(model:Model) extends MainFrame {
title = "app"
val parameters = new FlowPanel() {
contents += new Label("Tempo: ")
contents += new ComboBox(Seq("80", "100", "120", "140"))
contents += new Label("Metric: ")
contents += new Label("Note: ")
}
contents = parameters
}
Run Code Online (Sandbox Code Playgroud)
但是当我试图追加另一个时:
class View(model:Model) extends MainFrame {
title = "app"
val parameters = new FlowPanel() {
contents += new Label("Tempo: ")
contents += new ComboBox(Seq("80", "100", "120", "140"))
contents += new Label("Metric: ")
contents += new Label("Note: ")
}
val controls = new FlowPanel() {
contents += new Button( "klop" )
}
contents = parameters
contents += controls
}
Run Code Online (Sandbox Code Playgroud)
它不起作用:
src/View.scala:40: error: type mismatch;
found : scala.swing.FlowPanel
required: String
contents += controls
^
one error found
Error: Build failed.
Run Code Online (Sandbox Code Playgroud)
我该怎么办?我尝试使用Container,但我不知道如何正确使用它.
MainFrame,正如您所发现的,只能包含一件事.
因此,你需要将两者parameters并controls到一些容器,旨在制定出多个其他容器.你已经用过了FlowPanel- 你可以再这样做.或者,一个BoxPanel方向Orientation.Vertical可能更像你的想法.
所以你将其他容器添加到其中BoxPanel,然后设置BoxPanelas MainFrame的内容.
| 归档时间: |
|
| 查看次数: |
663 次 |
| 最近记录: |