如何向MainFrame内容添加多个组件

cie*_*bor 1 swing scala

我想制作几个面板的窗口.我可以将一个附加到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,但我不知道如何正确使用它.

Rex*_*err 5

MainFrame,正如您所发现的,只能包含一件事.

因此,你需要将两者parameterscontrols到一些容器,旨在制定出多个其他容器.你已经用过了FlowPanel- 你可以再这样做.或者,一个BoxPanel方向Orientation.Vertical可能更像你的想法.

所以你将其他容器添加到其中BoxPanel,然后设置BoxPanelas MainFrame的内容.