TextField Document model

Richard Bair richard.bair at oracle.com
Thu Oct 18 13:16:52 PDT 2012

> Sure.  How do I proceed with this?  Create a Jira issue and then submit the
> changes that way?

Yes, that would be best. If the code is relatively simple, then that is all you need to do. If it is more complex, then (bear with me) you will need to sign and send in the Oracle Contributor Agreement which gives oracle joint copyright so that we can relicense for mobile / embedded / licensees / etc. I'm guessing this one falls into the former category (adding a couple setters is not a big deal).

>> Content should be pluggable on a given TextInputControl, or whether it
> should require subclassing.
> Subclassing seems a bit inconvenient.  To control the input on every text
> field on a form, all the fields would need to be custom components.  This
> would mean that there would be very few TextFields in my app, I would have
> just MyTextField everywhere.  Also, how would I code it?  If I was just
> using setContent() I would do something like:
> firstField.setContent(new
> RestrictedLengthContent(Person.FIRST_NAME_LENGTH));
> lastField.setContent(new RestrictedLengthContent(Person.LAST_NAME_LENGTH));
> How would I do that in subclasses and still use SceneBuilder?  Maybe there
> would be a way in SceneBuilder to allow the use of a parameterized
> constructor with a custom parameter, but that seems pretty complex.

With subclassing, I might have done something like:

public class BetterTextField extends TextField {
    private IntegerProperty maxLength = new SimpleIntegerProperty(this, "maxLength", -1);
    // getters / setters

    // any other properties your ideal text field would have -- maybe a regex for validation, etc

    private static final class BetterContent extends Content {
        private IntegerProperty maxLength;
        // other properties

        // implementation....

    public BetterTextField() {
        super(new BetterContent());
        BetterContent content = (BetterContent) getContent();
        content.maxLength = maxLength; // alias the property

Then in FXML:

<?import com.mycompany.controls.BetterTextField?>
<BetterTextField maxLength="10" />

Now in Scene Builder I'm not sure this is well handled at present, it was on the task list for 8, although those plans haven't been finalized. It does something, but it might just be an empty box on the form, I'm not sure (depends on whether they are figuring out the classpath).

The theory was that some things (like maxLength) should just be added to TextField in the future, and we wanted to have some FormattedTextField (or whatnot) that would handle the other cases. These are all subclasses, so that's fine. If I were to do a SearchField, it would be a subclass. So for most cases it seemed a subclass would be done anyway. Also I think the TextField's Content does special things with regards to \n \t etc that are set on the field, so if you replace with a custom Content, you might want to wrap the original one to avoid problems. 

>> might fail in the control & in the skin
> I am pretty new to this, and I have not really addressed the Skin and
> Behavior aspects of everything.  Is there a good place to learn how this
> all is intended to work together?  It sounds like this is to break apart
> the PLAF Look and the PLAF Feel.  (Also, a FX skin is more about how things
> are painted, and is not the definition that some products use where a
> different skin completely rearranges the UI.)

Jonathan and Paru did a talk on this at JavaOne, as did Gerrit. 

Go to http://oracle.com/javaone
Click on JavaOne Technical Sessions link

I haven't tried to watch them yet via that page, but in theory it should work.


More information about the openjfx-dev mailing list