I've tried using wild cards in CSS selectors for JavaFX UI (TableView), but that doesn't seem to work, although JavaFX CSS reference notes that it's based on CSS version 2.1:
JavaFX Cascading Style Sheets (CSS) is based on the W3C CSS version
2.1 with some additions from current work on version 3.
For example:
TableColumnHeader[id|="column"] > .label
{
-fx-graphic: url("ico.png");
}
The above CSS is an attempt to show an icon "ico.png" on all column headers of a TableView
TableColumnHeader is the type selector for the table's column header Node
.label is the style class for the Label node rendered within the column header
[id|="column"] is similar to the example mentioned here: https://www.w3.org/TR/CSS21/selector.html#matching-attrs
The id of column header is inherited from its TableColumn. The id is set on the TableColumn object as follows: tableColumn.setId("column-"+ columnName) where columnName is a String variable
The above CSS doesn't work. Any variation that includes [id=...], or any other attribute other than id doesn't work.
Is this a limitation in JavaFX? or is there a way to make it work?
Related
I have created a simple grid with one column:
public MyGrid() {
addComponentColumn(this::getIcon).setClassNameGenerator(i -> "icon-img");
setItems(/** some items */);
setClassName("sidebar-grid");
}
And I have a css theme called mangaTheme. I use it like this #Theme("mangaTheme"). In the mangaTheme folder I have styles.css file with the following content:
.icon-img {
padding: 0;
}
.sidebar-grid {
width: 102px;
margin: auto;
margin-left: -30%;
}
The sidebar-grid css properties are applied properly as the grid is moved, but the icon-img properties are not applied whatsoever:
The classnames are applied:
What am I doing wrong or missing? I have also read this guide: https://cookbook.vaadin.com/dynamic-grid-cell-styling
EDIT: After configuring my workspace as was mentioned in the answer this is the resulting structure, but it still does not seem to function properly.
What you're missing is that the cell <td> element is inside the shadow DOM of the vaadin-grid component, and thus cannot be styled with global CSS. To style parts of components that are inside the component's shadow DOM, you need to inject the CSS into the component.
In the Cookbook example, this is done through the themeFor parameter in the annotation that loads the stylesheet:
#CssImport(themeFor = "vaadin-grid", value = "./recipe/dynamicgridcellstyling/dynamic-grid-cell-styling.css")
In your theme folder, however, you can do the same thing by putting that CSS in a stylesheet called vaadin-grid.css in the components subfolder, i.e.:
themes/mangaTheme/components/vaadin-grid.css
Another thing you're missing is that the classname is applied to the <td> cell, but the padding is on the vaadin-grid-cell-content element slotted into the cell, not the cell itself, so you need to rewrite your selector:
.icon-img ::slotted(vaadin-grid-cell-content) {
padding: 0;
}
(The sidebar-grid CSS class works fine as-is because it's applied to the vaadin-grid root element, which is in the page's regular DOM.)
Maybe a really newbie's question....
I'm starting learning JavaFX in a FMXL Application using the Scene Builder, by reading this tutorials:
http://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm
So once i applied some changes, an issue with this 2 IDs came up... I might have missed or confused something about them...
Can anyone tell me in which cases they are used one or another?
id you use to set a CSS ID to your Component, for example <Text id="welcome-text" .../> and in your stylesheet you have something like #welcome-text { font-size: 16pt; } so this will be applied to your Text.
fx:id you use if you want to work with your Components in your Controller class, where you annotate them with #FXML Text myWelcomeText.
The fx:id is the identity associated to component in fxml to build a controller, and the id is used for css.
I took a look at an FXML document generated using the JavaFX Scene Builder. You access controls from Java Controller with the fx:id. (edit) I stand corrected, the id does matter.
You can apply css from the FXML document like this:
<Slider id="css_id" fx:id="myslider" styleClass="style_name" .../>
(Replace slider with any control)
And Java controller interaction:
#FXML
Slider myslider;
In JavaFX id is used to set a CSS ID to a component. And fx:id is used for accessing that component in code (i.e. in a controller class). fx:id works like a components name.
I used to gwt 2.5.1, java 1.6.
when used grid,
I want to centerd just grid header.
No data, Only Header.
Source
.getGrid().getColumnModel().getColumns().get(i).setAlignment(HorizontalAlignment.CENTER);
But,
Both are aligned.
So,
What Can I do?
Thank you.
Use DOM inspector and fish out the style that corresponds to your header cell.
If you named your column as "test" then the style may be named something like "x-grid3-td-test".
Add the following to your stylesheet:
.x-grid3-td-test* {
text-align: center;
}
Maybe a really newbie's question....
I'm starting learning JavaFX in a FMXL Application using the Scene Builder, by reading this tutorials:
http://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm
So once i applied some changes, an issue with this 2 IDs came up... I might have missed or confused something about them...
Can anyone tell me in which cases they are used one or another?
id you use to set a CSS ID to your Component, for example <Text id="welcome-text" .../> and in your stylesheet you have something like #welcome-text { font-size: 16pt; } so this will be applied to your Text.
fx:id you use if you want to work with your Components in your Controller class, where you annotate them with #FXML Text myWelcomeText.
The fx:id is the identity associated to component in fxml to build a controller, and the id is used for css.
I took a look at an FXML document generated using the JavaFX Scene Builder. You access controls from Java Controller with the fx:id. (edit) I stand corrected, the id does matter.
You can apply css from the FXML document like this:
<Slider id="css_id" fx:id="myslider" styleClass="style_name" .../>
(Replace slider with any control)
And Java controller interaction:
#FXML
Slider myslider;
In JavaFX id is used to set a CSS ID to a component. And fx:id is used for accessing that component in code (i.e. in a controller class). fx:id works like a components name.
How to change single element of the widget style in GWT. I would like to create new version of TextBox style, so that only the border color changed to red, for example.How to get to the style responsible for the TextBox?
I tried to create new style
.gwt-TextBox.invalid {
border-color: red;
}
but it does not work.
Make sure you add class invalid to your TextBox:
textBox.addStyleName("invalid");
Use CssResource to associate your CSS file with GWT: http://code.google.com/webtoolkit/doc/latest/DevGuideUiCss.html#cssfiles