This discussion is archived
7 Replies Latest reply: Apr 30, 2013 5:49 AM by 943372 RSS

Custom FXML tag

943372 Newbie
Currently Being Moderated
Hi,

is it possible to derive from existing fx control (TableView, ListView, etc.), add functionality and define a custom fxml tag for it? For instance derive from ListView and draw some custom things in the list but choose in SceneBuilder the list orientation?

Regards
Oliver
  • 1. Re: Custom FXML tag
    shakir.gusaroff Expert
    Currently Being Moderated
    is it possible to derive from existing fx control (TableView, ListView, etc.), add functionality and define a custom fxml tag for it?
    It is possible.
    http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#custom_components
  • 2. Re: Custom FXML tag
    943372 Newbie
    Currently Being Moderated
    Thanks that's great. It works. I derived from ListView and my class is rendered as ListView in SceneBuilder. If I change the orientation from VERTICAL to HORIZONTAL of my custom ListView it is shown correctly in SceneBuilder but it will not be saved.
  • 3. Re: Custom FXML tag
    943372 Newbie
    Currently Being Moderated
    Probably this is a bug:

    I added MyListView in fxml as tag. When I open the fxml in SceneBuilder a dialog appears to adjust the classpath. After I have done this all works as it seems. But when I save, the fxml is not changed. If I choose Save As also the changes in my custom tag are saved.
  • 4. Re: Custom FXML tag
    daniel Journeyer
    Currently Being Moderated
    Hi,

    What do you mean by 'it will not be saved'.

    Did you change the value from within SceneBuilder, or within your custom class constructor?
    SceneBuilder does not save values that do not need to be saved.

    When you write:

    <fx:root type="<some standard javafx type>" .../>

    then what SceneBuilder will instantiate is "<some standard javafx type>" - therefore you will not see any customization you
    made in your custom type constructor.
    I will even argue that you shouldn't make any such customization in your constructor - instead you should make them in
    your fxml file - this way you will be able to change them by editing your fxml file in SceneBuilder.

    The only exception is if your custom type adds new properties - in that case the default values for these
    properties should be in your custom type constructor. However, for any property belonging to your
    custom type super class (<some standard javafx type>) - then the custom value should be in
    the fxml file - not in the constructor.

    Note - you should have a look at the examples that are delivered with SB 1.1 - in particular at the
    UnlockCustom example.
    http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html
    (click on Samples)


    best regards,

    -- daniel
  • 5. Re: Custom FXML tag
    943372 Newbie
    Currently Being Moderated
    Thanks for your replay.
    My test is quite simple:
    public class MyListView extends ListView<Label>
    {
         //~ Instance fields --------------------------------------------------------
    
         private String myProperty;
    
         //~ Constructors -----------------------------------------------------------
    
         /**
          * Creates a new MyListView object.
          */
         public MyListView()
         {
              super();
         }
    
         //~ Methods ----------------------------------------------------------------
    
         public void setMyProperty(String myProperty)
         {
              this.myProperty = myProperty;
         }
    
         public String getMyProperty()
         {
              return myProperty;
         }
    }
    In the fxml:
    <AnchorPane id="myPane" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                     <MyListView id="myListView" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" myProperty="my test value prop" />
                </AnchorPane>
    If I change in SceneViewer the orientation property of the MyListView I see that the list changes in SceneBuilder. But the orientation attribute is not saved in the fxml file.

    If I choose "Save As" and define a new fxml file the corresponding line the fxml is stored correclty:
    <MyListView id="myListView" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" myProperty="my test value prop" orientation="HORIZONTAL" />
  • 6. Re: Custom FXML tag
    daniel Journeyer
    Currently Being Moderated
    Hmmm... Yes this looks like a bug. You might want to log it: https://javafx-jira.kenai.com/browse/DTL
    Just make sure you're running with the latest SceneBuilder!

    -- daniel
  • 7. Re: Custom FXML tag
    943372 Newbie
    Currently Being Moderated
    There's coming up a dialog on each SceneBuilder start when I open the fxml which asks to adjust the classpath. MyListView class cannot be found. If I adjust the classpath, SceneBuilder works. But the classpath setting is not saved in the fxml.
    If I add the classpath entry manually in the fxml like this
    <?scenebuilder-classpath-element ../../../target/classes?>
    SceneBuilder is now saving the orientation property correctly. But on each start of SceneBuilder the classpath setting dialog is coming up. There is no need to change something in the dialog, I only have to check the checkbox "Set up classpath" and click the apply button (for the classpath entry which is already in the list). Also a but I think. I will file it as a bug. I am using SceneBuilder 1.1 b25.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points