关于AnchorPane的问题

时间:2017-01-31 09:57:41

标签: javafx scalafx

我现在正在学习Javafx和Scalafx,我有一个名为Room的类,其中包含名称:String,width:Long,length:Long和position:Insets和此类中有一个方法呈现,它返回一个scalafx .scene.Node

   def render()={
   val stack=new StackPane
   val vbox=new VBox
   vbox.getChildren.addAll(new Text(name))
   stack.getChildren.addAll(new Rectangle(width,length),vbox)
   Node.sfxNode2jfx(stack)
   }

我有一个名为house的类,其中包含Room

列表
   val room_list:Seq[Room]

我也有渲染方法:

   override def render=
   {
     val ap=new AnchorPane
   for(i <- 0 until room_list.length)
   {
    AnchorPane.setLeftAnchor(room_list(i).render,room_list(i).position.left)
    AnchorPane.setRightAnchor(room_list(i).render,room_list(i).position.right)
    AnchorPane.setTopAnchor(room_list(i).render,room_list(i).position.top)
    AnchorPane.setBottomAnchor(room_list(i).render,room_list(i).position.bottom)
  }
}

最后我想在主类中绘制这个AnchorPane,但实际上我得到的是,所有这些房间都设置在左上角,这意味着AnchorPane的for循环是完全没用的,为什么?

0 个答案:

没有答案
相关问题