...
AttributedString
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Text text = new Text("Hello Bold World"); TextStyle style = new TextStyle(); Font font = text.getFont(); Font boldFont = Font.font(font.getFamily(), FontWeight.BOLD, font.getSize(); style.setFont(boldFont); text.setStyle(6, 10, style); root.getChildren().add(text); |
CSS AttributedString
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Text text = new Text("Hello Bold World"); TextStyle style = new TextStyle(); style.getStyleClass().add("bold"); text.setStyle(6, 10, style); root.getChildren().add(text); scene.getStylesheets().add("file://mysheet.css"); |
...
In addition, the option to set a class name and id should for a TextStyle should be available:
TextStyle#getStyleClass().add(String className);
TextStyle#setId(String id);
DOM
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Paragraph paragraph = new Paragraph(); Text text0 = new Text("Hello "); Text text1 = new Text("Bold"); Text text2 = new Text(" World"); Font font = paragraph.getFont(); Font boldFont = Font.font(font.getFamily(), FontWeight.BOLD, font.getSize(); text1.setFont(boldFont); paragraph.getChildren().addAll(text0, text1, text2); root.getChildren().add(paragraph); |
CSS DOM
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Paragraph paragraph = new Paragraph(); Text text0 = new Text("Hello "); Text text1 = new Text("Bold"); Text text2 = new Text(" World"); text1.getStyleClass().add("bold"); paragraph.getChildren().addAll(text0, text1, text2); root.getChildren().add(paragraph); scene.getStylesheets().add("file://mysheet.css"); |
...
AttributedString
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Text text = new Text("Hello \uFFFC World"); Image img = new Image("file:///myimage.png"); Font font = text.getFont(); FontMetrics fm = Toolkit.getToolkit().getFontLoader().getFontMetrics(font); GlyphMetrics gm = new GlyphMetrics() gm.setDescent(fm.getDescent()); gm.setAscent(img.getHeight() - fm.getDescent()); gm.setWidth(img.getWidth()); TextStyle style = new TextStyle(); style.setGlyphMetrics(gm); text.setStyle(6, 7, style); ImageView imgView = new ImageView(img); root.getChildren().addAll(text, imgView); //every time a layout happens Path p = new Path(); p.getElements().addAll(text.impl_getRangeShape(6, 7)); p.setLayoutX(text.getLayoutX()); p.setLayoutY(text.getLayoutY()); Bounds bounds = p.getBoundsInLocal(); double x = bounds.getMinX() + text.getLayoutX(); double y = bounds.getMinY() + text.getLayoutY(); imgView.setLayoutX(x); imgView.setLayoutY(y); |
...
- This case can't be expressed using CSS with an Attributed String API
- Image is vertically aligned at the bottom of the text layout
DOM
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Paragraph paragraph = new Paragraph(); Text text0 = new Text("Hello "); ImageView imgView = new ImageView(); imgView.getStyleClass().add("imgView1"); Text text2 = new Text(" World"); paragraph.getChildren().addAll(text0, imgView, text2); root.getChildren().add(paragraph); scene.getStylesheets().add("file://mysheet2.css"); |
...
Overview
Content Tools
ThemeBuilder