Thursday, April 4, 2013

JavaFX TitledPane

javafx.scene.control.TitledPane is a panel with a title that can be opened and closed.

The panel in a TitledPane can be any Node such as UI controls or groups of nodes added to a layout container.

It is not recommended to set the MinHeight, PrefHeight, or MaxHeight for this control. Unexpected behavior will occur because the TitledPane's height changes when it is opened or closed

Example:

TitledPane
TitledPane


package javafx_titledpane;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFX_TitledPane extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        TitledPane titledPane = new TitledPane();
        titledPane.setText("My icon");
        
        Image image = new Image("http://goo.gl/kYEQl");
        ImageView imageView = new ImageView();
        imageView.setImage(image);
        titledPane.setContent(imageView);
        
        StackPane root = new StackPane();
        root.getChildren().add(titledPane);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setTitle("java-buddy.blogspot.com");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}


Next:
- Display multi images in JavaFX TitledPanes


No comments:

Post a Comment