JasonTolotta
JasonTolotta

Reputation: 160

FXForm2 - Lookup a Scene Element

The following creates a simple window displaying the following fields:

The following Java code displays the content:

public class ProxyDemo extends Application {
    private FXForm<Proxy> fxForm;
    private StackPane mainPane = new StackPane();

    static enum ProxyType {
        DIRECT, HTTP, HTTPS, FTP, SOCKS;
    }

    static class Proxy {
        private final ObjectProperty<ProxyType> proxyType = new SimpleObjectProperty<ProxyType>();
        private final StringProperty proxyHost = new SimpleStringProperty();
        private final IntegerProperty proxyPort = new SimpleIntegerProperty();
        private final StringProperty proxyExclusions = new SimpleStringProperty();

        public Proxy(ProxyType proxyType, String proxyHost, int proxyPort, String proxyExclusions) {
            this.proxyType.set(proxyType);
            this.proxyHost.set(proxyHost);
            this.proxyPort.set(proxyPort);
            this.proxyExclusions.set(proxyExclusions);
        }

        public ProxyType getProxyType() {
            return proxyType.get();
        }

        public String getProxyHost() {
            return proxyHost.get();
        }

        public int getProxyPort() {
            return proxyPort.get();
        }

        public String getProxyExclusions() {
            return proxyExclusions.get();
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public void start(Stage primaryStage) throws Exception {
        Proxy proxy = new Proxy(ProxyType.DIRECT, "", 0, "");
        fxForm = new FXFormBuilder<>().source(proxy).build();

        mainPane.getChildren().addAll(fxForm);

        Scene root = new Scene(mainPane);

        primaryStage.setTitle("Demo");
        primaryStage.setScene(root);
        primaryStage.show();
    }

    public static void main(String... args) {
        ProxyDemo.launch(args);
    }
}

The following is my attempt to lookup the Proxy Type.

fxForm.getScene().lookup("#proxyType");

It is my intention to Disable the fields when the Proxy Type is DIRECT, otherwise enable them.

Is the "proxyType" a Combobox type?

What is the ID of this field that FXForm2 assigns?

How does FXForm2 assign the IDs?

Upvotes: 1

Views: 168

Answers (1)

JasonTolotta
JasonTolotta

Reputation: 160

My questions are solved.

1. Is the proxyType a Combobox type?

No, the proxyType is a ChoiceBox.

2. What is the ID of this field that FXForm2 assigns?

#proxyType-form-editor

3. How does FXForm2 assign the IDs?

The interactive control is always suffixed with "-form-editor".

e.g. proxyHost will have an ID of #proxyHost-form-editor.

The associated label will have the ID #proxyHost-label.

References

FXForm2 GitHub - Wiki

https://github.com/dooApp/FXForm2/wiki/Style-your-form-with-css

Upvotes: 2

Related Questions