Gabriel95 / scalafx

Automatically exported from code.google.com/p/scalafx
Other
0 stars 0 forks source link

Cannot assign a ScalaFX object to scene.root #23

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Cannot assign a ScalaFX object to "scene.root". An attempt to do so result in 
compilation error:

For instance attempt to compile code below:

object AutoCenterDemo extends JFXApp {
  stage = new Stage {
    title = "AutoCenterDemo"
    scene = new Scene {
      // Assignment to 'root' fails with "type mismatch" error
      root = new StackPane {
        padding = Insets(20)
        content = new Rectangle {
          width = 200
          height = 200
          fill = Color.DEEPSKYBLUE
        }
      }
    }
  }
}

results in compilation error:

    error: type mismatch;
    found   : scalafx.scene.layout.StackPane
    required: javafx.scene.Parent
    root = new StackPane {

A work around is to either use explicit:

  import scalafx.scene.Parent.sfxParent2jfx

or reference ".delegate":

      root = new StackPane {
        padding = Insets(20)
        content = new Rectangle {
          width = 200
          height = 200
          fill = Color.DEEPSKYBLUE
        }
      }.delegate

Original issue reported on code.google.com by jpsacha on 15 Jan 2013 at 1:44

Attachments:

GoogleCodeExporter commented 8 years ago
A possible fix is to add an overloaded `root_=(v: Parent)` method to 
`scalafx.scene.Scene`, so there are two:

  def root_=(v: jfxs.Parent) {
    root() = v
  }

  def root_=(v: Parent) {
    root() = v.delegate
  } 

Original comment by jpsacha on 15 Jan 2013 at 3:28

GoogleCodeExporter commented 8 years ago
The suggested fix worked with both my current applications.

Original comment by Alain.Fa...@gmail.com on 17 Jan 2013 at 3:34