π¬ 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);
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);
setPreserveRatio(true) to keep the original image aspect ratio.
This ensures your images look neat and professional across all resolutions.
π§ Practice Zone β Create & Experiment
- Display your college name using a
Textobject with custom color and font. - Show a college logo using
ImageViewwithsetFitWidth()andsetPreserveRatio(). - Try combining text and image side-by-side in a
HBox. - Add hover effects that change image opacity when the mouse enters and leaves.
π‘ Each pixel you place is a piece of art β go build your visual story with JavaFX!