A TextArea
contains a scroll pane internally. The three things you need to make transparent to make the text area appear transparent are
- The text area iteself
- The viewport for the text area's internal scroll pane
- The content pane that displays the text inside the scroll pane
The CSS rule for this is
.text-area, .text-area .viewport, .text-area .content {
-fx-background-color: transparent ;
}
Complete example:
TransparentTextArea.java:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class TransparentTextArea extends Application {
@Override
public void start(Stage primaryStage) {
TextArea textArea = new TextArea();
StackPane root = new StackPane(textArea);
Scene scene = new Scene(root, 400, 400);
scene.getStylesheets().add("transparent-text-area.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
transparent-text-area.css:
.root {
-fx-background-color: linear-gradient(to bottom right, white 0%, cornflowerblue 100% );
}
.text-area, .text-area .viewport, .text-area .content {
-fx-background-color: transparent ;
}
