0

Is there a way to adjust the Brightness of the current Scene ?

I tried this solution: Change brightness of whole scene but this is not working for me.

    public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        VBox parent = new VBox();
        parent.getChildren().add(new Label("Examples"));

        HBox urlArea = new HBox(new Label("Text:"));
        TextField textField = new TextField();
        urlArea.getChildren().add(textField);
        parent.getChildren().add(urlArea);

        Button button = new Button("Count Words");
        button.setOnAction(event -> {
            if (textField.getText().isEmpty()) {
                System.err.println("TextField is Empty!");
            } else {
                System.out.println(counter(textField.getText()));
            }
        });
        parent.getChildren().add(button);

        // Possible Fix from StackOverflow
        // Sadly no changes
        Label fix = new Label("Fix colorAdjust whole scene.");
        fix.setVisible(false);
        fix.setManaged(false);

        // Change Brightness of Scene
        // Not Working. But i can see slight differents in the letters
        ColorAdjust setBrightness = new ColorAdjust();
        Button buttonBrightness = new Button("Brightness 0.1");
        buttonBrightness.setOnAction(event -> {
            setBrightness.setBrightness(0);
            parent.setEffect(setBrightness);
        });
        parent.getChildren().add(buttonBrightness);

        primaryStage.setScene(new Scene(parent));
        primaryStage.setTitle("Testing Frame");
        primaryStage.setHeight(200.0);
        primaryStage.setWidth(200.0);
        primaryStage.setResizable(false);
        primaryStage.show();

    public static void main(String[] args) {
        launch(args);
    }
    }

Im totaly new to JavaFx and this is my test area.

Detrua
  • 59
  • 6

1 Answers1

2

So I found the error by myself. Hovering about things and read the description may help sometimes. I thought that 0.1 is the darkest possible option but it was -1. In this case 0 is Default.

// Change Brightness of Scene
// Not Working. But i can see slight differents in the letters
ColorAdjust setBrightness = new ColorAdjust();
Button buttonBrightness = new Button("Brightness to 1");

buttonBrightness.setOnAction(event -> {
    setBrightness.setBrightness(0); **// VALUE FROM -1 to 1**
    parent.setEffect(setBrightness);
});
parent.getChildren().add(buttonBrightness);
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Detrua
  • 59
  • 6