NBKRIST - Java Hub : Displaying Text and Images in JavaFX

πŸ’¬ Expert View

You might be thinking β€” β€œImages and text? That’s too basic!” πŸ˜… But trust me β€” these are the building blocks of every great GUI! Using them smartly gives life to your apps β€” from dashboards to login screens. Experiment, style, and align β€” make your interface tell a story πŸŽ¨πŸ–ΌοΈ

Understanding Text Display in JavaFX

JavaFX provides multiple ways to display text on the screen. You can use Label for short messages or Text for styled and positioned text. These classes allow customization of font, size, color, and alignment β€” essential for designing user-friendly interfaces.

Label label = new Label("Welcome to NBKRIST - JavaFX!");
label.setFont(Font.font("Verdana", 18));
label.setTextFill(Color.DARKBLUE);

Text message = new Text(100, 120, "Learning JavaFX is fun!");
message.setFont(Font.font("Arial", FontWeight.BOLD, 22));
message.setFill(Color.CORNFLOWERBLUE);
    
πŸ’‘ Tip: Use Label for simple UI text (like button titles or info), and Text when you need precise positioning and font styling.

Displaying Images in JavaFX

You can easily display images using Image and ImageView classes. Image loads the file, and ImageView displays it on the scene. You can scale, rotate, or apply effects to make your UI visually appealing.

Image img = new Image("file:college_logo.png");
ImageView view = new ImageView(img);
view.setFitWidth(200);
view.setPreserveRatio(true);
    
Sample JavaFX Image Display
πŸ’‘ Always use setPreserveRatio(true) to keep the original image aspect ratio. This ensures your images look neat and professional across all resolutions.

🧠 Practice Zone β€” Create & Experiment

πŸ’‘ Each pixel you place is a piece of art β€” go build your visual story with JavaFX!