How to work with TextArea background in JavaFX?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to work with TextArea background in JavaFX?



I have an image with frame at transparent background and im looking to put it as background for TextArea.
Using google i found 2 ways to make it:



1)by placing


"-fx-background-image: url(...);"



into the


TextArea.setStyle();



2) just to make transparent background using


"-fxbackground-color: transparent;"



Make an image as another object, paste both objects at same location and add text area after image into the group.



But there's not worked any way. I have found also some ways by using CSS, but on my current project i havn't this one and would like to avoid, if possible.



The main case is that I can't make transparent background, it still white. Can someone give me an advice, what im doing wrong and example of working code?



background frame isn't square-type, so i really need a transparent background.




1 Answer
1



But there's not worked any way. I have found also some ways by using CSS, but on my current project I haven't this one and would like to avoid, if possible.



You are already using CSS. There's no way of avoiding using CSS here, unless you want to use your own implementation of the TextArea's skin.


TextArea



You need to use a CSS stylesheet that makes the background of the content area and the ScrollPane's viewport transparent:


ScrollPane


@Override
public void start(Stage primaryStage)
TextArea textArea = new TextArea();
textArea.getStyleClass().add("framed");

Scene scene = new Scene(new StackPane(textArea));
scene.getStylesheets().add("style.css");
primaryStage.setScene(scene);
primaryStage.show();


.framed.text-area
/* set size to picture size */
-fx-pref-height: 958;
-fx-pref-width: 958;
-fx-min-height: 958;
-fx-min-width: 958;
-fx-max-height: 958;
-fx-max-width: 958;

/* necessary padding to not cover the speech bubble with text */
-fx-padding: 95 135 329 90;

/* some image of a speech bubble from the web */
-fx-background-image: url(http://res.freestockphotos.biz/pictures/15/15674-illustration-of-a-cartoon-speech-bubble-pv.png);


.framed.text-area .scroll-pane .viewport,
.framed.text-area .content
-fx-background-color: null;






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS