ProgressBar with animated stripes [duplicate] - javafx

I wonder if it is possible to make a progressbar with the appearance,"progressbar Animated bootstrap". With stripes going sideways.
http://getbootstrap.com/2.3.2/components.html#progress

ProgressBar with Static Stripes
Here is a JavaFX ProgressBar which looks like a static striped progress bar from Bootstrap.
The stripe gradient is set entirely in css, the Java code is just a test harness.
File: striped-progress.css
.progress-bar > .bar {
-fx-background-color: linear-gradient(
from 0px .75em to .75em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
File: StripedProgress.java
import javafx.animation.*;
import javafx.application.Application;
import javafx.event.*;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;
/** Displays progress on a striped progress bar */
public class StripedProgress extends Application {
public static void main(String[] args) { launch(args); }
#Override public void start(final Stage stage) {
ProgressBar bar = new ProgressBar(0);
bar.setPrefSize(200, 24);
Timeline task = new Timeline(
new KeyFrame(
Duration.ZERO,
new KeyValue(bar.progressProperty(), 0)
),
new KeyFrame(
Duration.seconds(2),
new KeyValue(bar.progressProperty(), 1)
)
);
Button button = new Button("Go!");
button.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent actionEvent) {
task.playFromStart();
}
});
VBox layout = new VBox(10);
layout.getChildren().setAll(
bar,
button
);
layout.setPadding(new Insets(10));
layout.setAlignment(Pos.CENTER);
layout.getStylesheets().add(
getClass().getResource(
"striped-progress.css"
).toExternalForm()
);
stage.setScene(new Scene(layout));
stage.show();
}
}
ProgressBar with Animated Stripes
JavaFX has good animation facilities which will allow you to animate the gradient within the progress bar if you wish.
One way to do that is to do a node lookup on the bar after the bar has been displayed on the screen and modify the style property of the bar in a Timeline, similar to the technique applied in: How to make an animation with CSS in JavaFX?
Personally, I find animated stripes on progress bars annoying.
Writing the actual code for this is left as an exercise for the reader.

In another answer I have explained how to do this.
Like jewelsea said, I animated the hole progress-bar with a timeline. But without a lookup or style change on runtime(both is not really recommended).
You must write a bit more css but then it runs smoothly and without much CPU usage.
Here the edited code from jewelsea:
File: StripedProgress.java
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.css.PseudoClass;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;
/**
* Displays progress on a striped progress bar
*/
public class StripedProgress extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(final Stage stage) {
ProgressBar bar = new ProgressBar(0);
bar.setPrefSize(200, 24);
Timeline task = new Timeline(
new KeyFrame(
Duration.ZERO,
new KeyValue(bar.progressProperty(), 0)
),
new KeyFrame(
Duration.seconds(2),
new KeyValue(bar.progressProperty(), 1)
)
);
// Set the max status
int maxStatus = 12;
// Create the Property that holds the current status count
IntegerProperty statusCountProperty = new SimpleIntegerProperty(1);
// Create the timeline that loops the statusCount till the maxStatus
Timeline timelineBar = new Timeline(
new KeyFrame(
// Set this value for the speed of the animation
Duration.millis(300),
new KeyValue(statusCountProperty, maxStatus)
)
);
// The animation should be infinite
timelineBar.setCycleCount(Timeline.INDEFINITE);
timelineBar.play();
// Add a listener to the statusproperty
statusCountProperty.addListener((ov, statusOld, statusNewNumber) -> {
int statusNew = statusNewNumber.intValue();
// Remove old status pseudo from progress-bar
bar.pseudoClassStateChanged(PseudoClass.getPseudoClass("status" + statusOld.intValue()), false);
// Add current status pseudo from progress-bar
bar.pseudoClassStateChanged(PseudoClass.getPseudoClass("status" + statusNew), true);
});
Button button = new Button("Go!");
button.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent actionEvent) {
task.playFromStart();
}
});
VBox layout = new VBox(10);
layout.getChildren().setAll(
bar,
button
);
layout.setPadding(new Insets(10));
layout.setAlignment(Pos.CENTER);
layout.getStylesheets().add(
getClass().getResource(
"/styles/striped-progress.css"
).toExternalForm()
);
stage.setScene(new Scene(layout));
stage.show();
}
}
And the full CSS:
File: striped-progress.css
.progress-bar:status1 > .bar {
-fx-background-color: linear-gradient(
from 0em 0.75em to 0.75em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status2 > .bar {
-fx-background-color: linear-gradient(
from 0.25em 0.75em to 1em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status3 > .bar {
-fx-background-color: linear-gradient(
from 0.5em 0.75em to 1.25em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status4 > .bar {
-fx-background-color: linear-gradient(
from 0.75em 0.75em to 1.5em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status5 > .bar {
-fx-background-color: linear-gradient(
from 1em 0.75em to 1.75em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status6 > .bar {
-fx-background-color: linear-gradient(
from 1.25em 0.75em to 2em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status7 > .bar {
-fx-background-color: linear-gradient(
from 1.5em 0.75em to 2.25em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status8 > .bar {
-fx-background-color: linear-gradient(
from 1.75em 0.75em to 2.5em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status9 > .bar {
-fx-background-color: linear-gradient(
from 2em 0.75em to 2.75em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status10 > .bar {
-fx-background-color: linear-gradient(
from 2.25em 0.75em to 3em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status11 > .bar {
-fx-background-color: linear-gradient(
from 2.5em 0.75em to 3.25em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}
.progress-bar:status12 > .bar {
-fx-background-color: linear-gradient(
from 2.75em 0.75em to 3.5em 0px,
repeat,
-fx-accent 0%,
-fx-accent 49%,
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}

If anyone is interested for the animation version of #jewelsea answer, please check the below code.
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;
/**
* Displays progress on a striped progress bar
*/
public class StripedProgress extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(final Stage stage) {
ObjectProperty<Node> node = new SimpleObjectProperty<>();
ProgressBar bar = new ProgressBar(0) {
#Override
protected void layoutChildren() {
super.layoutChildren();
if (node.get() == null) {
Node n = lookup(".bar");
node.set(n);
int stripWidth = 10;
IntegerProperty x = new SimpleIntegerProperty(0);
IntegerProperty y = new SimpleIntegerProperty(stripWidth);
Timeline timeline = new Timeline(new KeyFrame(Duration.millis(35), e -> {
x.set(x.get() + 1);
y.set(y.get() + 1);
String style = "-fx-background-color: linear-gradient(from " + x.get() + "px " + x.get() + "px to " + y.get() + "px " + y.get() + "px, repeat, -fx-accent 50%, derive(-fx-accent, 30%) 50%);";
n.setStyle(style);
if (x.get() >= stripWidth * 2) {
x.set(0);
y.set(stripWidth);
}
}));
timeline.setCycleCount(Animation.INDEFINITE);
progressProperty().addListener((obs, old, val) -> {
if (old.doubleValue() <= 0) {
timeline.playFromStart();
}
});
}
}
};
bar.setPrefSize(200, 24);
Timeline task = new Timeline(
new KeyFrame(
Duration.ZERO,
new KeyValue(bar.progressProperty(), 0)
),
new KeyFrame(
Duration.seconds(10),
new KeyValue(bar.progressProperty(), 1)
)
);
Button button = new Button("Go!");
button.setOnAction(actionEvent -> task.playFromStart());
VBox layout = new VBox(10);
layout.getChildren().setAll(bar, button);
layout.setPadding(new Insets(10));
layout.setAlignment(Pos.CENTER);
stage.setScene(new Scene(layout));
stage.show();
}
}

Related

How to remove innser shadow in Text field

I want to remove the inner shadow in TextField.
Here is css.
-fx-font-size: 12px;
-fx-font-family: "Segoe UI Semibold";
-fx-pref-width:250px;
-fx-pref-height:35px;
-fx-background-radius:0px;
Try adding this line:
-fx-background-color: -fx-text-box-border, -fx-control-inner-background;
The problem is that it is NOT shadow. It is a specially decorated background. So making it transparent or putting a key which its value is transparent will work well.
.text-field {
-fx-text-box-border: transparent;
-fx-background-color: transparent;
}
.text-field:focused {
-fx-faint-focus-color: transparent; /*JavaFX 8*/
-fx-focus-color: transparent; /*JavaFX 2.2*/
}
The style code above(style.css) will generate a text field without any border and background and make it clear. By the way putting -fx-border-color or -fx-faint-color instead of transparent in -fx-background-color is completely fine since their value is transparent.
Edit: I'm adding now a little example code.
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.scene.layout.Pane;
public class TextFieldDemo extends Application {
public void start(Stage primaryStage) {
TextField textField = new TextField();
textField.setPromptText("TextField");
textField.setMaxWidth(100);
textField.setLayoutX(50);
textField.setLayoutY(25);
textField.setFocusTraversable(false);
Rectangle background = new Rectangle(40, 20, 120, 40);
background.setStyle("-fx-arc-width: 40px; -fx-arc-height: 40px;-fx-fill: yellow;");
Scene scene = new Scene(new Pane(background, textField), 200, 80);
scene.getStylesheets().add("style.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Example Output:
Example Image

JavaFX TableView Rows color

I would like to update my TableView rows color depending on the data in the cell, so I used a pseeudoClass to reference the style in Css. the rows are colored as I wanted but, it lost the selection and the mouse hover effect, now I have a colored rows without any indication to the selected row. here is my code:
PseudoClass myPseudoClass = PseudoClass.getPseudoClass("dtta_dep");
PseudoClass myPseudoClass1 = PseudoClass.getPseudoClass("dtta_dest");
fplTableView.setRowFactory(tv -> new TableRow<FlightPlan>() {
#Override
public void updateItem(FlightPlan item, boolean empty) {
super.updateItem(item, empty);
this.setFocused(true);
this.setHover(true);
System.out.println("myPseudoClass = "+myPseudoClass.getPseudoClassName());
pseudoClassStateChanged(myPseudoClass, (! empty) && item.Dep_aerodomProperty().get().equalsIgnoreCase("DTTA"));
pseudoClassStateChanged(myPseudoClass1, (! empty) && item.Dest_aerodomProperty().get().equalsIgnoreCase("DTTA"));
}
});
getData();
for (int i = 0; i < listF.size(); i++) {
System.out.println(listF.get(i).Dep_aerodomProperty().get());
}
selectWithService();
});
the css file :
.table-row-cell {
-fx-background-color: linear-gradient(white 0%, white 90%, #e0e0e0 90%);
}
.table-row-cell:selected {
-fx-background-color: linear-gradient(#95caff 0%, #77acff 90%, #e0e0e0 90%);
}
.table-row-cell:dtta_dep .table-cell {
-fx-text-fill: red;
-fx-background-color:beige;
}
.table-row-cell:dtta_dest .table-cell {
-fx-text-fill: blue;
-fx-background-color:greenyellow;
}
Use -fx-background instead of -fx-background-color on the table-row-cell to set the non-selected background. You can use -fx-selection-bar to set the selected color. The text fill is defined in a table cell with the -fx-text-background-color color, (i.e. the text fill for text over a -fx-background), so you can override those for the text fill in the cells.
.table-row-cell {
-fx-background: linear-gradient(white 0%, white 90%, #e0e0e0 90%);
-fx-selection-bar: linear-gradient(#95caff 0%, #77acff 90%, #e0e0e0 90%);
}
.table-row-cell:dtta_dep {
-fx-text-background-color: red;
-fx-background: beige;
}
.table-row-cell:dtta_dest {
-fx-text-background-color: blue;
-fx-background:greenyellow;
}

JAVAFX - Transparent bar on button using CSS

I want my button to have a transparent black bar on the bottom with a opacity of 75%. The button name should appear on top of the black bar. I have drawn a draft below.
So far I have tried with no success:
.button{
-fx-background-color: #5a9bdc;
-fx-font-size: 16;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
-fx-text-fill: #ffffff;
}
.button:hover {
-fx-background-color: #97c0dc;
}
UPDATE:
So this is how my css looks:
.button-stats.parent{
-fx-background-color: #5a9bdc;
-fx-font-size: 16;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
-fx-text-fill: #ffffff;
}
.button-stats:hover {
-fx-background-color: #97c0dc;
}
.button-stats.element{
padding: 20px;
color: rgba(255,255,255,.4);
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
Here is a sample, it isn't going to be exactly what you want, but may help you in getting to where you want. It is based upon button styles found in modena.css in the jfxrt.jar that ships with Java 8.
Images are shown for unhovered and hovered and armed states (armed is when the button is pressed and the shadow is removed).
I did not provide info here for a focused state, so you will need to develop that yourself if you want it.
super-button.css
.button {
-custom-solid-button-color: lightgreen;
-custom-translucent-button-color: rgba(00, 80, 00, 0.75);
-custom-button-color:
linear-gradient(to bottom,
-custom-solid-button-color 0%,
-custom-solid-button-color 64%,
-custom-translucent-button-color 65%);
-fx-background-color: -custom-button-color;
-fx-background-insets: 0;
-fx-background-radius: 0;
-fx-text-fill: whitesmoke;
-fx-padding: 3.333333em 0.666667em 0.333333em 0.666667em;
-fx-font-size: 30px;
-fx-effect: dropshadow(gaussian, black, 10, 0, 3, 3);
}
.button:hover {
-custom-solid-button-color: derive(lightgreen, 20%);
-fx-effect: dropshadow(gaussian, goldenrod, 10, 0, 3, 3);
}
.button:armed {
-custom-solid-button-color: derive(lightgreen, -10%);
-fx-effect: null;
-fx-background-insets: 2 2 0 0;
}
SuperButton.java
import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.*;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SuperButton extends Application {
private static final String BACKGROUND_IMAGE_LOC =
"http://edugeography.com/images/great-barrier-reef/great-barrier-reef-04.jpg";
#Override
public void start(Stage stage) {
Button button = new Button("I \u2764 Sea Turtles");
ImageView background = new ImageView(
new Image(BACKGROUND_IMAGE_LOC, 400, 0, true, true)
);
StackPane layout = new StackPane(
background,
button
);
StackPane.setAlignment(button, Pos.BOTTOM_CENTER);
StackPane.setMargin(button, new Insets(0, 0, 15, 0));
Scene scene = new Scene(layout);
scene.getStylesheets().add(getClass().getResource(
"super-button.css"
).toExternalForm());
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Getting the translucent area at the base is slightly tricky, especially because you are applying a drop shadow effect. What happens with a drop shadow effect is that the drop shadow is visible through the translucent area. Normally, when you have an opaque foreground, you can see the shadow through the foreground, but when you have a translucent foreground, the shadow mars the translucent effect a bit. To understand what I mean, review the above images and note the difference between the translucent area in the images with and without a drop shadow involved.
So you might want to rethink the design to not use the drop shadow. There are ways around this using clips, but it gets a bit more complicated and you cannot achieve it using just CSS (you will also need to write some custom skin code in Java, which I won't demonstrate here).
Try
.button {
-fx-opacity: 0.7;
}

How not differ tableview focused rows from other rows?

I have a tableview in JavaFX and I don't want focused row to differ from others. The problem is that when I click on a row and select it, the row's bottom border goes away. Which css property makes it and how can I fix that?
In the attached screen shot all rows selected, and my last click was on "nature" row.
MCVE:
Main.java:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
HBox hBox = new HBox();
Scene scene = new Scene(hBox, 300, 275);
scene.getStylesheets().add("main.css");
TableView<Keyword> keywordsTable = new TableView<>();
TableColumn<Keyword, String> wordColumn = new TableColumn<>();
ObservableList<Keyword> data = FXCollections.observableArrayList();
wordColumn.setCellValueFactory(new PropertyValueFactory<>("word"));
keywordsTable.getColumns().add(wordColumn);
keywordsTable.setItems(data);
keywordsTable.setRowFactory(param -> {
TableRow<Keyword> row = new TableRow<>();
row.addEventFilter(MouseEvent.MOUSE_CLICKED, e -> {
keywordsTable.requestFocus();
if (!row.isEmpty() && e.getButton().equals(MouseButton.PRIMARY)) {
changeRowSelection(keywordsTable, row.getItem(), row.getIndex());
}
e.consume();
});
row.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
keywordsTable.requestFocus();
e.consume();
});
return row;
});
keywordsTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
data.add(new Keyword("one"));
data.add(new Keyword("two"));
data.add(new Keyword("three"));
data.add(new Keyword("four"));
data.add(new Keyword("five"));
hBox.getChildren().add(keywordsTable);
primaryStage.setScene(scene);
primaryStage.show();
}
private void changeRowSelection(TableView table, Keyword keyword, int index) {
if (table.getSelectionModel().getSelectedItems().contains(keyword)) {
table.getSelectionModel().clearSelection(index);
} else {
table.getSelectionModel().select(index);
}
}
public static void main(String[] args) {
launch(args);
}
public class Keyword {
private final SimpleStringProperty word;
public Keyword(String word) {
this.word = new SimpleStringProperty(word);
}
public String getWord() {
return word.get();
}
public void setWord(String word) {
this.word.set(word);
}
}
}
main.css:
.table-row-cell:focused {
-fx-background-insets: 0;
-fx-padding: 0;
}
.list-cell:filled:selected,
.tree-cell:filled:selected,
.table-row-cell:filled:selected,
.tree-table-row-cell:filled:selected,
.table-row-cell:filled > .table-cell:selected,
.tree-table-row-cell:filled > .tree-table-cell:selected {
-fx-background: #C7E8EA;
-fx-table-cell-border-color: #26ABD7 !important;
-fx-text-fill: black;
}
.table-row-cell:focused {
-fx-background-insets: 0 0 0;
}
.table-cell {
-fx-background-insets: 0 !important;
}
It worked for me with the following css
see for information : https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html
.table-view {
-my-bg-color: #C7E8EA;
-my-bd-color: violet;
}
.table-row-cell {
-fx-background: -my-bg-color;
-fx-background-color: -my-bd-color, -fx-background;
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0;
-fx-text-fill: black;
}
.table-cell {
-fx-padding: 0.166667em; /* 2px, plus border adds 1px */
-fx-background-color: null;
-fx-border-color: transparent -my-bd-color transparent transparent;
-fx-cell-size: 2.0em; /* 24 */
-fx-text-fill: -fx-text-background-color;
}
Note the custom css variable definition in .table-view. This is not mandatory, just for convenience.

How to get rid of white border around JavaFX Textview

I have a white border around my TextArea that I cannot get rid of
Heres the code:
textArea = new TextArea();
textArea.getStyleClass().add("textArea");
textArea.setWrapText(true);
And the css:
.textArea{
-fx-background-insets: 0 0 0 0, 0, 1, 2;
-fx-background-radius: 0;
-fx-text-fill: white;
-fx-border-color: #2a2a2a;
-fx-border-width: 0;}
.textArea .content{
-fx-background-color: #2a2a2a;
-fx-border-color: #2a2a2a;
}
Can anyone help?
This works in my test case:
.text-area, .text-area .content {
-fx-background-color: #2a2a2a ;
-fx-background-radius: 0 ;
}
.text-area {
-fx-text-fill: white ;
}
Test code:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class TextAreaBorderTest extends Application {
#Override
public void start(Stage primaryStage) {
TextArea textArea = new TextArea();
BorderPane root = new BorderPane(textArea);
root.setPadding(new Insets(24));
Scene scene = new Scene(root);
scene.getStylesheets().add("text-area-border-test.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I added
.root {
-fx-background-color: black ;
}
to the CSS in order to test.

Resources