CSS parsing error with font face in javafx - java

I am using a tableview and would like to edit the font inside of it, however since tableview cannot implement a custom font with it's "setStyle" I am forced to rely on CSS
CSS code:
#font-face {
font-family: '8BIT WONDER';
src: url('8BITWONDERNominal.ttf');
font-weight: normal;
font-style: normal;
}
//Style of entire tableView
.table-view{
-fx-font-family: "8BIT WONDER" ;
-fx-text-alignment: center;
}
//Style of each column in the tableView
.table-view .table-column{
-fx-font-size: 15px;
}
//Style of each table cell
.table-view .table-cell{
-fx-font-size: 12px;
-fx-alignment: center;
}
Java line calling the CSS:
leaderScene.getStylesheets().add("leaderboard.css");
The CSS is parsing and is loading, the fonts and styles perfectly display on the table however the terminal still gives this error reguardless
WARNING: CSS Error parsing
file:/D:/Overhaul%20with%20Leaderboard/Overhaul/leaderboard.css: Unexpected
TOKEN [:] at [4,15]
Mar 29, 2018 10:21:45 AM com.sun.javafx.css.StyleManager
loadStylesheetUnPrivileged
INFO: Could not load #font-face font
[file:/D:/Overhaul%20with%20Leaderboard/Overhaul/8BITWONDERNominal.ttf]
Mar 29, 2018 10:33:21 AM com.sun.javafx.css.StyleManager
loadStylesheetUnPrivileged
If there isn't a fix, is there a way to allow the terminal to ignore this error since the css is being loaded and functions correctly?

Related

How do i use custom fonts through JavaFx CSS?

I've attempted adding a custom font to my program using CSS and i can't get it to work, is anyone able to help?
This is what i've got at the moment:
#font-face
{
font-family: walterturncoat;
src: url("../resources/fonts/walterturncoat.ttf");
}
.label
{
-fx-font-family: "Walter Turncoat";
-fx-text-fill: #ffffff;
-fx-font-size: 20pt;
-fx-effect: dropshadow(gaussian, #000000, 10, 0, 2, 2);
}
The url works as i used a similar path for an image (just /images/ instead of /fonts/) and i was able to get the font to work outside of CSS in the bulk of the program but i intend to be using it a lot so having it in CSS would be ideal.

How do I make a media-query for a canvas made in Java?

Media queries in CSS file has no effect on the GUI made in javaFX.
I have made a canvas using javaFX. I have used FXML to setup the different GUI elements. Then I have used a CSS file to style everything. The problem now is, that I want to make it responsive. When I try to use media queries in the CSS file, nothing happens.
.userMenu {
-fx-max-height: 30;
-fx-max-width: 130;
-fx-background-color: rgba(255, 255, 255, 0.5);
-fx-padding: 10px;
-fx-background-radius: 12px;
}
#media only screen and (min-width: 300px) {
.userMenu {
-fx-max-height: 150;
-fx-max-width: 300;
-fx-background-color: rgba(255, 255, 255, 0.5);
-fx-padding: 10px;
-fx-background-radius: 12px;
}
}
I expect the userMenu box to rescale when crossing 300px width.
Just found this when searching myself and the simple answer is: You don't.
From the official docs:
While the JavaFX CSS parser will parse valid CSS syntax, it is not a fully compliant CSS parser. One should not expect the parser to handle syntax not specified in this document.
#-keyword statements are ignored.
I guess one needs to write Java code for that ¯\_(ツ)_/¯
Edit:
After looking at the JavaFX 8 docs there are two supported #-rules: #import and #font-face. But that's all.

How to change font on css?

I'm trying to manipulate the font in Agenda from jfxtras (javafx).
I have a css file linked to it.
I figured out how to make it black and bold as well.
.AgendaText {
-fx-text-fill: BLACK;
-fx-font-weight: bold;
}
But I don't know how to change the font to say, Arial.
Thanks,
Browser will try to take first font, second font and if it wont be able to find it it will serve a sans serif system font
.AgendaText {
font-family: arial, helvetica, sans-serif
}

JavaFX doesn't change the font of its components

I specified a font in a style .css file:
-fx-background-color: #1e1c1e;
-fx-font-family: "Segoe UI", Helvetica, Arial, sans-serif;
but IDEA underlines the second line:
"mismatched property value null".
Then I tried to set a font in the following way:
inputField.setFont(Font.font("Segoe UI"));
All the same. Font won't change. I'd like to ask your help because I'm stucked with this issue.

How to add CSS inline in Vaadin?

Is it possible to add inline CSS code programmatically?
Like, I have defined a CSS separator like this:
.hr{
border-top: 1px solid black;
padding-bottom: 10px;
}
Now I sometimes want to have it in a different color or a different size.
Would I have to create further .hr-black, .hr-blue css styles and apply them separately by .addStyleName()? Or can I somehow set the color programmatically?
No, you can only change CSS at specific component using component.addStyleName(), but you can use it dynamically, like this:
if (condition)
component.addStyleName("black");
else
component.addStyleName("blue")

Categories