palexdev / MaterialFX

A library of material components for JavaFX
GNU Lesser General Public License v3.0
1.21k stars 122 forks source link

How to set our own TextFormatter on MFXTextField #247

Closed chuckdu21 closed 1 year ago

chuckdu21 commented 2 years ago

Hi, I'd like to set my own TextFormatter on a MFXTextField but i get this error: formatter is already used in other control

I tried to unbind the textformatter, even on the boundField but my TextFormatter won't set. (I tried the same textformatter on a default TextField and it's working).

Here's a sample of my code:


public class MFXDateTimeField extends MFXTextField {
    UnaryOperator<TextFormatter.Change> filter;

    public MFXDateTimeField() {
        super();
        this.filter = c -> {
            if (c.isAdded()) {
                c.setRange(c.getRangeStart(),
                        Math.min(c.getControlText().length(), c.getRangeStart() + c.getText().length()));
            }
            return c;
        };
        this.setTextFormatter(new TextFormatter<Object>(filter));

How can i "force" to set my TextFormatter or something like this ?

mahfoud09 commented 2 years ago

this.delegateSetTextFormatter(new TextFormatter(filter));

mahfoud09 commented 2 years ago

What the version of Materielfx you use

Le mer. 26 oct. 2022 à 08:31, chuckdu21 @.***> a écrit :

Can't find this method in MFXTextField .....

— Reply to this email directly, view it on GitHub https://github.com/palexdev/MaterialFX/issues/247#issuecomment-1291616533, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKORZ5WOHVOZ3CH2IVMKYE3WFDM3RANCNFSM6AAAAAARB6JYFE . You are receiving this because you commented.Message ID: @.***>

chuckdu21 commented 2 years ago

I deleted my answer because i was on 11.13.0^^ I just did the update and i found the method. Now it's working ! thx

But another issue: getPositionCaret always returns 0

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

Closed for inactivity.