javafx-2, remove focus highlighting via CSS - css

I want to remove the blue border that surronds a TableView when it is focused.
I checked into the caspian.css, that for most components like Button and TextField, does something like:
.table-view:focused {
-fx-background-color: -fx-focus-color,-fx-box-border,-fx-control-inner-background;
-fx-background-insets: -1.4, 0, 1;
-fx-background-radius: 1.4, 0, 0;
/*....*/
-fx-padding: 1; /* 0.083333em; */
}
My question is about CSS, at the end. Can I override this pseudoclass specification in my stylesheet instead of trying to turn the colors into transparent?

Yes you can. In your stylesheet define exactly the same CSS selector with JavaFX CSS properties of your own choice like this:
.table-view:focused {
-fx-background-color: red /* or transparent or other preferred color */,-fx-box-border,-fx-control-inner-background;
-fx-background-insets: -1.4, 0, 1;
-fx-background-radius: 1.4, 0, 0;
/*....*/
-fx-padding: 1; /* 0.083333em; */
}

Because JavaFX 8 has a new theme 'modena' but with the same old problem I want to make an update of the answer of Uluk Biy and give some further information:
If you ever wonder, where some style came from, you can have a look into modena.css. You can find this css file in jfxrt.jar, which itself could be found in your JRE or JDK installation directory. On Ubuntu 14.04 the jdk home is usually under
/usr/lib/jvm/java-8-oracle/
and the jfxrt.jar should be here
/usr/lib/jvm/java-8-oracle/jre/lib/ext
Open the jar-file and have a look in the directory /com/sun/javafx/scene/control/skin/modena where you will find the modena.css
Starting from line 406 you can see a headlines like this
/* ==== BUTTON LIKE THINGS ============================================== */
The css under this section specifies the background and border for a lot of controls and containers. You simply have to search for your target class. I will show it for buttons as an example:
For the button class the following css is specified
-fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color;
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
For some reasons they do not use borders, but use multiple backgrounds simulating a border like look. So if you want to remove the border only, you have to adjust the background and inset property.
Finally if you want to remove the focused effect you have to override this default css
.button:focused,
.toggle-button:focused,
.radio-button:focused > .radio,
.check-box:focused > .box,
.menu-button:focused,
.choice-box:focused,
.color-picker.split-button:focused > .color-picker-label,
.combo-box-base:focused,
.slider:focused .thumb {
-fx-background-color: -fx-focus-color, -fx-inner-border, -fx-body-color, -fx-faint-focus-color, -fx-body-color;
-fx-background-insets: -0.2, 1, 2, -1.4, 2.6;
-fx-background-radius: 3, 2, 1, 4, 1;
}
for the controls of you choice with the default definition for background and insets from above. E.g. for buttons:
.button:focused {
-fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color;
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
}

Related

JavaFX TreeTableView Css for unfocused selected line

I have a problem with CSS on TreeTableView.
For TableView when I define CSS like this :
.table-row-cell:selected{
-fx-background-color: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-fill: white;
}
The selected rows have text in white even if I click out of the table
For TreeTableView I have defined CSS like this :
.tree-table-row-cell:selected{
-fx-background-color: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-fill: white;
}
The selected rows have text in white but when I click out of the table the text change to black
Does someone know how can I solve this ?
Thank you
Try setting the text fill on the cells themselves, instead of the row cells:
.tree-table-row-cell:selected{
-fx-background-color: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
}
.tree-table-row-cell:selected .tree-table-cell,
.tree-table-cell:selected {
-fx-text-fill: white;
}
You probably also want
.tree-table-row-cell:selected .tree-disclosure-node .arrow {
-fx-background-color: white ;
}
For a slightly different approach:
The default behavior of the modena stylesheet is to set the text fill to a "looked up color" called -fx-text-background-color. This is set to a "ladder", which is a function based on the value of another looked-up color called -fx-background. The background color of the rows and cells is defined in terms of -fx-background.
The way the "ladder" works is if the intensity of -fx-background is less than 45%, the ladder evaluates to -fx-light-text-color (white), between 46% and 59% it evaluates to -fx-dark-text-color (black) and above that to -fx-mid-text-color (grey).
So typically, you can simply change -fx-background (instead of -fx-background-color) and the text will change to something appropriate:
.tree-table-row-cell:selected{
-fx-background: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
}
In your case, this won't quite give you what you want. The color you chose as the background isn't dark enough to trigger the light text color; the intensity is about 58%, so it evaluates to black.
If you use a darker background, say #d1531f, then you see the white text with no additional changes.
You can fix this by adjusting the ladder itself so the intensity thresholds are different:
.tree-table-row-cell:selected{
-fx-background: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-background-color: ladder(
-fx-background,
-fx-light-text-color 60%,
-fx-dark-text-color 61%,
-fx-dark-text-color 69%,
-fx-mid-text-color 70%
);
}
or perhaps just by bypassing the ladder entirely and setting -fx-text-background-color directly to the light text color:
.tree-table-row-cell:selected{
-fx-background: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-background-color: -fx-light-text-color;
}
This is more complex (perhaps) but is more in the style of the default CSS. It works with the cells without explicitly having to change the CSS for those (basically, looked-up colors are inherited), and the disclosure arrow automatically has the same color as the text.

How to separate a border and an effect?

Currently, I have a button with the following CSS:
Button {
-fx-text-fill: -fx-color-text;
-fx-font: 15pt "Raleway SemiBold";
-fx-background-color: -fx-color-theme;
-fx-background-insets: 0, 0, 0, 0, 0, 1, 2;
-fx-background-radius: 0;
-fx-padding: 4px 20px;
/* -fx-effect: innershadow(two-pass-box, white, 2, 0.2, 0, 0); */
-fx-border-insets: 0;
-fx-border-color: black;
}
And it looks like this:
And I'm trying to add an inner shadow to the button. I want the border to show on the outside of this button, which should result in something like this:
I made that in Swing. However, when I try and apply my inner shadow, it draws on top of my border, as shown:
I've tried setting the border insets to -1 (because there isn't an insets property for the effect), but that just moved the effect with it:
My question is: What can I do to ensure that I can see my border around the outside, but keep my effect on the inside?
EDIT: I'm pretty sure that this is a bug in OpenJFX and I've submitted a bug report. Here's some quick code you can use to reproduce the issue:
public class App extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Region example = new Region();
example.setMaxWidth(100);
example.setMaxHeight(100);
example.setEffect(new InnerShadow(BlurType.GAUSSIAN, Color.RED, 10, 0.04, 0, 0));
example.setStyle("-fx-background-color: white; -fx-border-color: BLUE; -fx-border-width: 5px;");
StackPane container = new StackPane();
container.setStyle("-fx-background-color: black;");
container.setAlignment(Pos.CENTER);
container.getChildren().add(example);
Scene scene = new Scene(container, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
}
I think the border is getting blended with the effect which is applied. And as you are pretty sure that it could be a bug in JavaFX rendering, below is one way to get it look the way you want.
You can consider the below solution as when you think like "I definitely want this look only !!" kind of thing :)
The idea is, instead of setting the effect, you paint the effect manually.
.button {
-fx-text-fill: #FFFFFF;
-fx-font: 15pt "Raleway SemiBold";
-fx-background-color: #000000, #720D4D, #D03A9A, #DD70B6, #B01378, #CC2C93, #D03A9A, #C81688;
-fx-background-insets: 0, 1, 1 2 2 1, 1 2 2 2, 2, 2 3 3 2, 2 3 3 3, 3;
-fx-background-radius: 0;
-fx-padding: 4px 20px;
-fx-border-insets: 0px;
-fx-border-radius: 0px;
-fx-border-width: 0px;
}
And the output is as below [ignore the font as I dont have the .tff ;)]:
And a closer look for verification purpose:
This may not be an actual solution, but can be one alternate (least case).

Highlight top of a JavaFX TableRow with css

I'm trying to figure out the CSS for highlighting the top of a TableRow. I'm using this for reordering rows so that anyone reordering them can tell where it will be inserted. Currently I've only been able to draw a rectangle around the row, but I just want the top line of that rectangle.
.table-row-cell.drag {
-fx-focus-color: #00a9d3;
-fx-faint-focus-color: #00a9d322;
-fx-highlight-fill: -fx-accent;
-fx-background-color:
-fx-focus-color,
-fx-control-inner-background,
-fx-faint-focus-color,
linear-gradient(from 0px 0px to 0px 5px, derive(-fx-control-inner-background, -9%), -fx-control-inner-background);
-fx-background-insets: -0.2, 1, -1.4, 3;
-fx-background-radius: 3, 2, 4, 0;
}
You could specify different -fx-background-insets for the sides. If one color should only appear on one side, the insets of the next color match the insets for the mark color except for the side that should be colored.
Furthermore I recommend using PseudoClass instead of a style class, since this way you don't need to make sure to not add a class multiple times.
final PseudoClass mark = PseudoClass.getPseudoClass("mark");
...
boolean marked = ...
row.pseudoClassStateChanged(mark, marked);
The following CSS is a bit simplified, but it should demonstrate the approach:
.table-row-cell:mark {
-fx-background-color: -fx-table-cell-border-color, red, -fx-background;
/* show red highlight of size 2 at the top */
-fx-background-insets: 0, 0 0 1 0, 2 0 1 0;
}

Gtk3 Transparent Container

I'm working on a Gtk3 application. Therefore I designed the window on Ubuntu with Glade 3.16.1.
I have a GtkWindow layout with a vertical seperating GtkPaned. Loading a CSS file I give the window a background image like this:
GtkWindow#window {
background-image: url("Glade Prototype/background.png");
}
But It seems like the layout component is drawn on it with a solid color and so the background image is only partially visible. You can see it
here
My first try was setting the background color of the layout transparent, but it didn't changed anything (Any other color works):
GtkPaned#mainLayout {
background-color: transparent;
/* OR: background-color: rgba(0, 0, 0, 0.0) */
/* OR: background-image: none */
}
Thanks for help,
Greetings Thomas
PS: Does anyone have a Glade version for Windows supporting Gtk3 (+CSS)? I only found Glade 3.8 (CSS supporting versions are e.g. 3.16 / 3.18) on their website.
Edit: Here a better example for this problem:
GtkWindow#window {
background-color: #00FF00;
}
GtkPaned#mainLayout {
background-color: rgba(255, 0, 0, 0.5)
}
-> Image with Alpha 50% / 0.5
You can see that it looks like a mix of red and white color. But i want that white color to disappear.
Edit2:
I've also tried overriding the draw function and drawing a transparent rectangle with Cairo -> No success. My code:
G_MODULE_EXPORT gboolean drawMainContainer(GtkWidget *widget, cairo_t *cr, gpointer data) {
guint width, height;
GdkRGBA color;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
cairo_rectangle (cr, 0, 0, width, height);
gtk_style_context_get_color (gtk_widget_get_style_context (widget),
0,
&color);
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_fill (cr);
return FALSE;
}

How to change the color of text in javafx TextField?

I want to change font color in TextField .I found -fx-background-color , -fx-border-color for changing the color of background and border but nothing for text.
Setting the -fx-text-fill works for me.
See below:
if (passed) {
resultInfo.setText("Passed!");
resultInfo.setStyle("-fx-text-fill: green; -fx-font-size: 16px;");
} else {
resultInfo.setText("Failed!");
resultInfo.setStyle("-fx-text-fill: red; -fx-font-size: 16px;");
}
The CSS styles for text input controls such as TextField for JavaFX 8 are defined in the modena.css stylesheet as below. Create a custom CSS stylesheet and modify the colors as you wish. Use the CSS reference guide if you need help understanding the syntax and available attributes and values.
.text-input {
-fx-text-fill: -fx-text-inner-color;
-fx-highlight-fill: derive(-fx-control-inner-background,-20%);
-fx-highlight-text-fill: -fx-text-inner-color;
-fx-prompt-text-fill: derive(-fx-control-inner-background,-30%);
-fx-background-color: linear-gradient(to bottom, derive(-fx-text-box-border, -10%), -fx-text-box-border),
linear-gradient(from 0px 0px to 0px 5px, derive(-fx-control-inner-background, -9%), -fx-control-inner-background);
-fx-background-insets: 0, 1;
-fx-background-radius: 3, 2;
-fx-cursor: text;
-fx-padding: 0.333333em 0.583em 0.333333em 0.583em; /* 4 7 4 7 */
}
.text-input:focused {
-fx-highlight-fill: -fx-accent;
-fx-highlight-text-fill: white;
-fx-background-color:
-fx-focus-color,
-fx-control-inner-background,
-fx-faint-focus-color,
linear-gradient(from 0px 0px to 0px 5px, derive(-fx-control-inner-background, -9%), -fx-control-inner-background);
-fx-background-insets: -0.2, 1, -1.4, 3;
-fx-background-radius: 3, 2, 4, 0;
-fx-prompt-text-fill: transparent;
}
Although using an external stylesheet is a preferred way to do the styling, you can style inline, using something like below:
textField.setStyle("-fx-text-inner-color: red;");
If you are designing your Javafx application using SceneBuilder then use -fx-text-fill(if not available as option then write it in style input box) as style and give the color you want,it will change the text color of your Textfield.
I came here for the same problem and solved it in this way.

Resources