I'm working with a Popover, which is used as a tooltip-like help-display for a Textfield.
It contains a Label and a TextArea as content and is created, when the user enters the text field. (Via FocusPropery.addListener )
I apply the style using:
popOver.getRoot().getStylesheets().add(...)
(as found in the documentation documentation )
This works for the TextArea, but only partialy for the label.
My Style looks like this:
*{
-tb-dark-grey: rgb(32,38,44);
}
.root {
-fx-base: -tb-dark-grey;
-fx-background: -tb-dark-grey;
-fx-control-inner-background: -tb-dark-grey;
}
This works very good in my main window. Including all Labels and TextAreas. Everything gets a dark-blue background with white text.
For the Label in the Popover however it changes only the text color to white but the background stays at the usual light grey.
I tried using the TextArea as a workaround. This works for the style. But it always steals the focus from the text field. This makes it impossible to type something. Disabling the TextArea works,but that changes the style of the TextArea.
I already tried appling the style as found in this other question.
I also tried getting the focus back with, which also did not work.
popup.Show(this.inputField)
this.inputField.requestFocus(); // also tried this with Platform.runLater
Your problem should be that Label doesn't use any of the colors you have overwritten in your .root style class. According to JavaFX CSS reference guide you can style the background of a Label by using fx-background-color.
Adding the following line to your stylesheet should do the trick:
.label {
-fx-background-color: -tb-dark-grey;
}
You can also apply the style individually for each label by creating a custom style class if you want to style labels differently:
CSS:
.custom-label {
-fx-background-color: -tb-dark-grey;
}
And then applying it to a specific label:
Label label = new Label("I am a label");
label.getStyleClass().add("custom-label");
Edit: You should probably be aware that your TextArea will not display the exact color you've defined in your stylesheet. If you check the Modena stylesheet, which is the default theme and style for JavaFX (how to find it is described here). You will find the following css for the TextArea content:
.text-area .content {
/*the is 1px less top and bottom than TextInput because of scrollpane border */
-fx-padding: 0.25em 0.583em 0.25em 0.583em; /* 3 7 3 7 */
-fx-cursor: text;
-fx-background-color:
linear-gradient(from 0px 0px to 0px 4px, derive(-fx-control-inner-background, -8%), -fx-control-inner-background);
-fx-background-radius: 2;
}
As you can see. The background color of the TextArea content is not exactly the -fx-control-inner-background that you have defined in your stylesheet, but a linear gradient that goes from a color derived from -fx-control-inner-background to the color you want. This might not even be noticeable for you, but could be good to know.
Setting the color of the TextArea background so that is it precisely your color could be done like this:
.text-area .content {
-fx-background-color: tb-dark-grey;
}
Related
Using JavaFX 15
There's a line of shadow below the border of the JavaFX FXML button.
is it possible to make it transparent using CSS? As I do not know which attribute it belongs to.
Picture of the button attached below
.btn{
-fx-background-color: black;
-fx-background-radius: 30px;
-fx-border-color: white;
-fx-border-radius: 30px;
-fx-border-width: 3px;
}
colored with black background and white borderline for visibility
It is possible that what you are seeing is the background spilling out past the border. Since you have customized the border thickness in the CSS, you may also need to adjust background insets.
See the CSS docs for Region https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#region
I have never seen this behaviour, but a nice reference for attributes available to the basic JavaFX-classes can be found here: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html
This could maybe be due to not overwriting all the standard JavaFX button style attributes.
I'm using ui-bootstrap-tpls-2.5.0.min.js. I changed dropdown-menu's backgorund color like this in specific html.
.dropdown-menu {
background-color: transparent;
box-shadow: none;
}
But it makes datepicker's background transparent too. I know why it happened, so I cleared that line but nothing changed.
So I want to change datepicker popup's background using CSS selector like this,
.datepicker .ul{
background-color: white;
}
//this is an example code.
what selector do I have to choose to change datepicker's background?
If this is what you require, you need to add these two styles that are highlighted.
Happy coding :)
Alright so I can't get this to work at all. I've checked the CSS analyzer in the scene builder and I came to the conclusion that the way to change the text color in a textarea is something similar to this:`
.text-area .text {
-fx-fill: #1e88e5;
-fx-font-size: 32px;
}`
Problem is that the color doesn't change nor does the font size. Where am I going wrong here?
How about this:
.text-area {
-fx-text-fill: #1e88e5;
-fx-font-size: 32px;
}
Update: the Style class text-area doesn't have a descendant named text. it has an immediate child named scroll-pane and a decendant named content .for more information see: this link
I am trying to override the default setting for selection. I did
::selection{
background: grey;
}
and it looks like that takes effect when the window is not focused, but when it is focused, it does not have effect and the default color appears. It is not working. What is the correct way to do this so that is has effect irrespective of the focus?
Edit I think I was wrong. I want to change the color of the selected text in <input> tag. How can I do that?
You're probably using Firefox, which needs the -moz prefix:
::selection {
color: fireBrick;
}
::-moz-selection {
color: fireBrick;
}
Demo: http://jsfiddle.net/N4AUY/
Note that you cannot group these together. One of these won't work, so the whole rule block breaks.
Should Work fine, See this demo. the problem seems to be due to something else
::selection
{
background: grey;
}
::-moz-selection
{
background: grey;
}
It is the default browser behavior which you cannot change, when window is not focused, the selected color changes to grey, may be it denotes that the text cannot be copied (kinda disabled selection), so we cannot control that color
Example 2
I am working on a GUI and I've run into a problem. If I set a button, label, or other widget to have a background color, the tooltip for that widget also takes the same background color. I tried editing the style sheet for the tooltip specifically and setting a different background color but it doesn't work. I also tried editing the palette for the widget but changing the color scheme for the tooltip background or text doesn't work either. Is there another way I can do this? I'd like to have consistency between all my tooltips.
Thanks!
You can do something like this to style a QToolTip in general.
QToolTip { color: #fff; background-color: #000; border: none; }
When you need to style QToolTips specifically, based on their parent widget you can use following syntax:
ParentWidgetName QToolTip { color: #333; background-color: #1c1c1c; border: none; }
Reading this will help you further.