0

I am now learning Javafx and Scalafx, I have got a class called Room, which holds name:String, width:Long, length:Long and a position:Insets and in this class there is a method render which returns a 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)
   }

and I have a class called house which holds a list of Room

   val room_list:Seq[Room]

and also I have a render method:

   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)
  }
}

at last I want to draw this AnchorPane in the main class, but actually what I got is that, all those rooms are setteled on the top left corner, which means the for loop for AnchorPane is compeletly useless, why?

Terry
  • 21
  • 1
  • 3
  • for(i <- 0 until room_list.length) { ap.getChildren.addAll(room_list(i).render) } Node.sfxNode2jfx(ap) – Terry Jan 31 '17 at 10:15
  • Can you explain what you're actually trying to achieve? Typically, overriding the render method is an advanced topic. In JavaFX/ScalaFX you define a scene, which is then rendered automatically. If you can tell me what you want to see, I can tell you how to create the scene you want. (Once a scene has been defined, you can interact with it and modify it - and, again, you don't need to do the rendering yourself.) – Mike Allen Feb 03 '17 at 15:08

0 Answers0