Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

FXML, css and -fx-font-family

913147Jan 25 2012 — edited Jan 25 2012
I'm trying to style an FXML layout with CSS and it's picking up changes to font size but not font family, unless it's a 'generic' font-name. Am I doing something wrong? The minimal example below displays in the default font (Consolas is a valid font which I can load with Font.font("Consolas", 32.0f); ). In any case, if there's a problem with Consolas it should fallback to monospace, shouldn't it?

Thanks,
Peter
(System: Win XP 32-bit)
----
My CSS
Label {
	-fx-font-size: 32pt;
	-fx-font-family: 'Consolas', monospace;
}
----
My FXML
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" >
	<children>
		<Label id="label" layoutX="80" layoutY="80" text="Test Text"/>
	</children>
</AnchorPane>
----
My main class
package javafxapplication2;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class JavaFXApplication2 extends Application {
	
	public static void main(String[] args) {
		Application.launch(JavaFXApplication2.class, args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
		Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
		final Scene scene = new Scene(root);
		final String css = getClass().getResource("Sample.css").toExternalForm();
		scene.getStylesheets().add(css);
		stage.setScene(scene);
		stage.show();
	}
}
Edited by: 910144 on 25-Jan-2012 03:46
add code tags
This post has been answered by john16384 on Jan 25 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2012
Added on Jan 25 2012
3 comments
11,379 views