How to Change Font Size in the Stylesheet of the Tables in Java?
To change the font size for tables, you need to change the height and/or weight of the table cell. You can do this by modifying their dimensions in their stylesheet by overriding the text-align property or changing one of these values: left or right with top or bottom.
SSCCE:
on Jan 01, 1970
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class FontSizeTest extends Application {
@Override
public void start(Stage primaryStage) {
Label label = new Label("Some text");
Region rect = new Region();
rect.getStyleClass().add("rect");
VBox vbox = new VBox(label, rect);
vbox.getStyleClass().add("vbox");
Slider slider = new Slider(6, 24, 12);
BorderPane root = new BorderPane(vbox, null, null, slider, null);
BorderPane.setMargin(slider, new Insets(10));
BorderPane.setAlignment(slider, Pos.CENTER);
root.styleProperty().bind(Bindings.format("-fx-font-size: %.2fpt;", slider.valueProperty()));
Scene scene = new Scene(root, 400, 400) ;
scene.getStylesheets().add("font-size-test.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
0
font-size-test.css:
on Jan 01, 1970
.rect {
-fx-min-width: 1em ;
-fx-max-width: 1em ;
-fx-min-height: 1em ;
-fx-max-height: 1em ;
-fx-background-color: cornflowerblue ;
}
.vbox {
-fx-spacing: 1em ;
-fx-padding: 1.5em ;
}
0
Based on the comments in the CSS file itself:
on Jan 01, 1970
RESIZING FOR DIFFERENT SCREEN DPI
-------------------------------
When the screen DPI changes Windows will use a different font size by default.
The default is 12px and can change to 15px or 18px depending on user
preference or screen DPI. On Mac the default is 13px and embedded will depend
on hardware. To make UI controls scale and be the right proportions for each of
these font sizes we base the padding (which controls size of control) on the
font size. This is done using the CSS measurement unit of a "em" where
(1em = font size). The default sizes are based on Windows default of 12px, as
a quick reference here are common px sizes in em units on windows.
Windows 12px -> em units -> Mac 13px |
----------------------------------------
1px -> 0.083333em -> 1.08px ~ 2px
2px -> 0.166667em -> 2.16px ~ 3px
3px = 0.25em
4px = 0.333333em
5px = 0.416667em
6px = 0.5em
7px = 0.583333em
8px = 0.666667em
9px = 0.75em
10px = 0.833333em
11px = 0.916667em
12px = 1em
0
If you want to change the font size of your table in Java, you can use a program such as TableStyle.
Java answers related to "javafx css text size"
javafx css text size mouse handler javafx package javafx.fxml does not exist package javafx.fxml does not exist java list length set text in edittext android how to change color text in Koltin string split method set text in edittext android how to change color text in Koltin set text in edittext android java read integer from text file into array scanner javafx css text size
View All Java queries
Java queries related to "javafx css text size"
Browse Other Code Languages
Abap ActionScript Assembly BASIC C C# C++ Clojure Cobol CSS Dart Delphi Elixir Erlang F# Fortran Go Groovy Haskell Html Java Javascript Julia Kotlin Lisp Lua Matlab Objective-C Pascal Perl PHP PostScript Prolog Python R Ruby Rust Scala Scheme Shell/Bash Smalltalk SQL Swift TypeScript VBA WebAssembly Whatever