【问题标题】:Scala Swing: how to get child component form BorderpanelScala Swing:如何从 Borderpanel 中获取子组件
【发布时间】:2012-09-17 16:40:36
【问题描述】:

如何获取 Scala Swing BorderPanel 上特定位置的子组件?我可以放置组件。在这种特殊情况下,我想检查 BorderPanel.Position.Centre 的组件。我也对,每个位置只能有一个子组件或空值:北、东等?

【问题讨论】:

    标签: scala scala-swing


    【解决方案1】:

    嗯,layout 是一个从组件到位置的映射,所以以下工作(不确定是否有更简单的方法):

    import scala.swing.SimpleSwingApplication
    import scala.swing.MainFrame
    import scala.swing.BorderPanel
    import scala.swing.Label
    
    object BorderLayoutTest extends SimpleSwingApplication {
    
      def top = new MainFrame {    
        contents = new BorderPanel {
    
          val label = new Label("hi")
    
          import BorderPanel.Position._
          layout(label) = Center
    
          println("North: " + layout.find(_._2 == North))   //None
          println("Center: "+ layout.find(_._2 == Center))  //Some( ... )
        } 
      }  
    }
    

    【讨论】:

      猜你喜欢
      • 2015-04-20
      • 1970-01-01
      • 2012-11-03
      • 2019-05-13
      • 1970-01-01
      • 2016-06-18
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多