I´d like to know how to implement the properties of Shape Class as described in Reference Guide?
Example:
I have a custom checkbox css:
.check-box-money .box {
-fx-border-color: #d8d8d8;
-fx-border-width: 4;
-fx-background-radius: 0;
-fx-background-color: -color-primary;
-fx-background-insets: 0 0 0 0, 0, 1, 2;
-fx-shape: "M21.1,21.1h-21l5.6-21h21L21.1,21.1z M1.4,20.1h19l5.1-19h-19L1.4,20.1z";
}
But the line of the shape is too thin, so I´d like to change.
So I tried to implement -fx-stroke-width but nothing worked.
Related
I want to create a chat box style around a TextArea in JavaFX. I have the following code:
TextArea ta = new TextArea();
ta.getStyleClass().add("chat-bubble");
VBox vb = new VBox(9);
VBox.setMargin(ta, new Insets(10,10,10,10));
vb.getChildren().addAll(ta);
Scene scene = new Scene(vb, 200, 300);
scene.getStylesheets().add("resources/ta.css");
stage.setScene(scene);
stage.show();
and the following CSS (resources/ta.css):
TextArea {
-fx-background-insets: 0;
-fx-background-color: transparent;
}
TextArea .scroll-pane {
-fx-background-color: transparent;
}
TextArea .scroll-pane .viewport{
-fx-background-color: transparent;
}
TextArea .scroll-pane .content{
-fx-background-color: transparent;
}
.chat-bubble {
-fx-shape: "M334.266,29.302c-4.143,0-7.5,3.358-7.5,7.5v210.632H177.423c-1.656,0-3.266,0.548-4.578,1.559L120,289.717v-34.783c0-4.142-3.358-7.5-7.5-7.5s-7.5,3.358-7.5,7.5v50.031c0,2.858,1.625,5.468,4.19,6.73c1.05,0.517,2.182,0.77,3.309,0.77c1.626,0,3.242-0.529,4.579-1.56l62.9-48.472h154.288c4.143,0,7.5-3.358,7.5-7.5V36.802 C341.766,32.659,338.409,29.302,334.266,29.302 M72.884,247.433H15V44.302h272.883c4.143,0,7.5-3.358,7.5-7.5s-3.357-7.5-7.5-7.5H7.5c-4.142,0-7.5,3.358-7.5,7.5v218.132c0,4.142,3.358,7.5,7.5,7.5h65.384c4.142,0,7.5-3.358,7.5-7.5S77.026,247.433,72.884,247.433z";
-fx-background-color: darkred;
-fx-padding: 3 3 10 3;
}
VBox {
-fx-background-color: transparent;
}
But the stroke width of the chat box is too thick:
I have tried all sorts of tweaks with border-width, stroke-width etc. in CSS and programmatically.
How do I go about setting the stroke width of the -fx-shape path?
enter image description here
I am new to CSS and I am trying to get rid of the white space (as seen in the image) in the drop menu of the combo box... setting the background black didn't work... this is my CSS for the combo box
.combo-box {
-fx-border-width : 1 ;
-fx-border-color : #29a8a6;
-fx-text-fill: #29a8a6;
-fx-border-radius: 50;
-fx-padding : 0;
-fx-background-color: #29a8a6;
-fx-background-radius: 50;
}
.combo-box .list-cell{
-fx-prompt-text-fill : #29a8a6;
-fx-text-fill: #29a8a6;
-fx-background-color: black;
-fx-padding : 2;
-fx-cell-border : 0;
-fx-border-width: 0;
-fx-border-radius: 50;
-fx-background-radius: 50;
}
To get rid of the white space in the drop down menu you can add this to your css file:
.combo-box .list-view {
-fx-background-color: black;
}
PS:
Whenever you are not sure which elements styling you need to change, you can make use of Scenic View to find out the element.
apparently the problem was the listview in the combo-box , so setting the insets to 0 solved my problem
.combo-box {
-fx-background-color:#29a8a6;
-fx-background-radius : 40;
}
.combo-box .list-view {
-fx-prompt-text-fill : #29a8a6;
-fx-background-color : black;
-fx-background-radius : 40;
-fx-insets : 0;
}
.combo-box .list-cell{
-fx-prompt-text-fill : #29a8a6;
-fx-text-alignment : CENTER;
-fx-background-radius : 40;
-fx-background-color : black;
}
I customized porgressbar using css but when i used -fx-pref-width for .bar it did not work.This is my css :
.super-fx-progress-bar {
-fx-background-color: transparent;
}
.super-fx-progress-bar .track{
-fx-background-color: transparent;
-fx-border-radius:20;
-fx-background-radius:20;
}
.super-fx-progress-bar .bar {
-fx-background-color: #0057e7,transparent,#6666ff;
-fx-background-insets: 1 1 1 3, 1 1 1 1, 1 1 2 3;
-fx-border-radius:20;
-fx-background-radius:20;
-fx-pref-width:2
/*What should i add to minimize width of bar when its value is indeterminated*/
}
You can do this by adding :
-fx-indeterminate-bar-length:value;
in progressbar class (you used .super-fx-progress-bar) :
I did this to show the differents results :
First style :
.super-fx-progress-bar {
-fx-background-color: transparent;
-fx-indeterminate-bar-animation-time:1.0;
-fx-indeterminate-bar-flip:true;
-fx-indeterminate-bar-escape:true;
-fx-indeterminate-bar-length:20;
-fx-min-height:5;
}
Second style :
.super-fx-progress-bar {
-fx-background-color: transparent;
-fx-indeterminate-bar-animation-time:1.0;
-fx-indeterminate-bar-flip:true;
-fx-indeterminate-bar-escape:true;
-fx-indeterminate-bar-length:60;
-fx-min-height:5;
}
In my application I have a specific styling that states that yellow should be used to represent required fields. In my grids, I have implemented this as follows:
.table-cell-required-field {
-fx-control-inner-background: -sif-required_field-color;
-fx-background-color:-fx-table-cell-border-color, -fx-control-inner-background;
-fx-border-color: deepskyblue deepskyblue deepskyblue deepskyblue ;
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0.0em;
-fx-text-fill: -fx-text-inner-color;
}
.table-cell-required-field:selected {
-fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-focus-color;
-fx-background-insets: 0, 1, 2;
}
This works just fine - however, when the table isn't focused, the selected field is staying -fx-focus-color rather than reverting back to the standard in modena which has it as gray - which is confusing the users.
I have tried to use focus as a psuedo class as well - but looking in ScenicView both cells show both selected and focused and this has no change.
Here is an example of what I need to happen when the table isn't focused:
However when I select the required field and then selected the other table it stays blue - I need this to go gray when it doesn't have focus.
I would appreciate any help in what I am missing.
Thanks!
Try
.table-cell-required-field {
-fx-control-inner-background: -sif-required_field-color;
-fx-background-color:-fx-table-cell-border-color, -fx-control-inner-background;
-fx-border-color: deepskyblue deepskyblue deepskyblue deepskyblue ;
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0.0em;
-fx-text-fill: -fx-text-inner-color;
}
.table-view .table-cell-required-field:selected {
-fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-selection-bar-non-focused;
-fx-background-insets: 0, 1, 2;
}
.table-view:focused .table-cell-required-field:selected {
-fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-focus-color;
-fx-background-insets: 0, 1, 2;
}
Typically for styling at this level I look at the default modena.css stylesheet, which you can extract from your jfxrt.jar file, or see at the OpenJFX source.
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;
}