Skip to main content

DocumentFilter and TextField?

2 replies [Last post]
ederbaum
Offline
Joined: 2006-01-11
Points: 0

Before the new javaFX "Compiled" version the code below was working perfectly.

import javafx.ui.*;
import javax.swing.JTextField;
import javax.swing.text.AbstractDocument;
import javax.swing.text.DocumentFilter;

class FilteredTextField extends TextField {
public attribute filter:DocumentFilter;
}

trigger on FilteredTextField.filter = newValue {
((AbstractDocument)super().textField.getDocument()).setDocumentFilter(filter);
}

But now, i can't even access the "textField" as a "JTextField" (now is "ObjectVariable").

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tball
Offline
Joined: 2003-06-10
Points: 0

There is a new UI library under development, which has javafx.gui.* packages. javafx.gui.TextField has a getJTextField() function which should directly provide what you need.

For the old javafx.ui.TextField (which will be replaced soon with the javafx.gui version), you can use createComponent(). Another issue with your code is that casting is done using an "at" operator instead of like Java does it. So your setDocumentFilter() code might look like:

((createComponent() as JTextField).getDocument() as AbstractDocument).setDocumentFilter(filter);

Replacing the above with getJTextField() is easier, yes? :-)

ederbaum
Offline
Joined: 2006-01-11
Points: 0

Thanks now is working:

public class MyTextField extends TextField {
public attribute filter:DocumentFilter on replace {
((createComponent() as JTextField).getDocument() as AbstractDocument).setDocumentFilter(filter);
};
}