1. Why was JavaFX removed from JDK after Java 11?
JavaFX was removed from the JDK to make the JDK smaller and more modular. It is now
maintained separately as OpenJFX. Implication: Developers must download JavaFX separately
and include required modules when building and distributing applications.
2. Which thread calls init(), start(), and stop()?
init() is called on the launcher thread (not the JavaFX Application Thread). start() and stop() are
called on the JavaFX Application Thread. Scene and Stage objects must be created and modified
only inside start() because they require the JavaFX Application Thread.
3. BorderPane vs GridPane
BorderPane arranges nodes in five regions (top, bottom, left, right, center). It is ideal for main
application layouts. GridPane arranges nodes in rows and columns, ideal for forms and structured
data input layouts.
4. StackPane and z-order
StackPane stacks children on top of each other. The last added node appears on top. You can
change z-order using toFront() or toBack() methods.
Example:
[Link]();
5. KeyEvent and MouseEvent example
You can trigger the same action using both a Button click and pressing Enter in a TextField.
Example:
[Link](e -> submit());
[Link](e -> submit());
6. Purpose of --module-path and --add-modules
--module-path tells the JVM where JavaFX libraries are located.
--add-modules specifies which JavaFX modules to include (e.g., [Link]).
Without them, the application will fail with 'module not found' errors.
7. Runnable JavaFX Application Example
Example:
public class Main extends Application {
@Override
public void start(Stage stage) {
Button btn = new Button("Click Me");
[Link](e -> [Link]("Hello, JavaFX!"));
Scene scene = new Scene(new StackPane(btn), 300, 200);
[Link](scene);
[Link]();
}
public static void main(String[] args) {
launch(args);
}
}
8. FXML and Controller
FXML separates UI design from logic. The FXML file defines layout, while the controller class
handles events and logic. UI elements are linked to controller variables using @FXML annotation.
9. Scene Graph vs Swing Paint
JavaFX uses a Scene Graph where UI elements are nodes in a tree structure. Swing uses a paint()
method for rendering. Scene Graph allows hardware acceleration and better performance for
animations and complex UIs.
10. Populating a TableView
TableView displays data in rows and columns. TableColumn defines how to extract properties from
objects.
Example:
TableColumn nameCol = new TableColumn<>("Name");
[Link](new PropertyValueFactory<>("name"));
[Link](observableList);