Swing 如何向大型机内容中添加多个组件

Swing 如何向大型机内容中添加多个组件,swing,scala,Swing,Scala,我想用很少的嵌板做窗户。我可以在大型机的内容中附加一个: 导入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 +=

我想用很少的嵌板做窗户。我可以在大型机的内容中附加一个: 导入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
}
但当我尝试附加另一个:

    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
    }
它不起作用:

src/View.scala:40: error: type mismatch;
 found   : scala.swing.FlowPanel
 required: String
  contents += controls
              ^
one error found
Error: Build failed.
我该怎么做?我试过使用一个容器,但我不知道如何正确使用它。

正如您所发现的,大型机只能包含一个东西

因此,您需要将参数和控件放置到设计用于布局多个其他容器的容器中。您已经为此使用了FlowPanel,您可以再次这样做。或者,一个方向的箱型面板。垂直可能更符合你的想法

因此,您可以将其他容器添加到BoxPanel,然后将BoxPanel设置为大型机的内容。

正如您所发现的,大型机只能包含一个内容

因此,您需要将参数和控件放置到设计用于布局多个其他容器的容器中。您已经为此使用了FlowPanel,您可以再次这样做。或者,一个方向的箱型面板。垂直可能更符合你的想法

因此,将其他容器添加到该BoxPanel,然后将该BoxPanel设置为大型机的内容