package canvastest; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.FontSmoothingType; import javafx.stage.Stage; public class CanvasFontSmoothingTest extends Application { @Override public void start(Stage stage) { Canvas canvas = new Canvas(600, 600); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill(Color.YELLOW); gc.fillRect(300, 0, 300, 600); gc.setFill(Color.BLACK); int y = 10; int p = 6; while (y <= 150) { gc.setFont((Font.font("Serif", p))); gc.setFontSmoothingType(FontSmoothingType.GRAY); gc.fillText ("GRAY on transparent", 10, y); gc.strokeText("GRAY on transparent", 10, 300+y); gc.setFontSmoothingType(FontSmoothingType.LCD); gc.fillText ("LCD on transparent", 10, 150+y); gc.strokeText("LCD on transparent", 10, 450+y); gc.setFontSmoothingType(FontSmoothingType.GRAY); gc.fillText ("GRAY on opaque", 310, y); gc.strokeText("GRAY on opaque", 310, 300+y); gc.setFontSmoothingType(FontSmoothingType.LCD); gc.fillText ("LCD on opaque", 310, 150+y); gc.strokeText("LCD on opaque", 310, 450+y); p += 3; y += p; } Scene scene = new Scene(new Group(canvas)); stage.setScene(scene); stage.show(); } public static void main(String argv[]) { launch(argv); } }