openplanning

Hướng dẫn và ví dụ JavaFX TitledPane

Xem thêm các chuyên mục:

Nhóm phát triển của chúng tôi vừa ra mắt website langlearning.net học tiếng Anh, Nga, Đức, Pháp, Việt, Trung, Hàn, Nhật, ... miễn phí cho tất cả mọi người.
Là một website được viết trên công nghệ web Flutter vì vậy hỗ trợ rất tốt cho người học, kể cả những người học khó tính nhất.
Hiện tại website đang tiếp tục được cập nhập nội dung cho phong phú và đầy đủ hơn. Mong các bạn nghé thăm và ủng hộ website mới của chúng tôi.
Hãy theo dõi chúng tôi trên Fanpage để nhận được thông báo mỗi khi có bài viết mới. Facebook

1- JavaFX TitledPane

TitledPane là một panel có tiêu đề, và panel này có thể mở rộng (expaned)  hoặc cụp lại (collapsed).
 
Constructor:

// Tạo một TitledPane không tiêu đề và không nội dung
TitledPane()

// Tạo một TitledPane với tiêu đề và nội dung.
TitledPane(String title, Node content)
Method:

public void setTitle(String title)
public void setContent(Node value)
public void setCollapsible(boolean value)
public boolean isCollapsible()
public void setAnimated(boolean value)
public void setExpanded(boolean value)
public boolean isExpanded()

.....

2- Ví dụ với TitledPane

TitledPaneDemo.java

package org.o7planning.javafx.titledpane;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class TitledPaneDemo extends Application {

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

  @Override
  public void start(Stage stage) {

      // Tạo TitledPane
      TitledPane titledPane = new TitledPane();
      titledPane.setText("Java");

      // Nội dung của TitledPane
      VBox content = new VBox();
      content.getChildren().add(new Label("Java Swing Tutorial"));
      content.getChildren().add(new Label("JavaFx Tutorial"));
      content.getChildren().add(new Label("Java IO Tutorial"));

      titledPane.setContent(content);
 
      // Sét titledPane đang mở
      titledPane.setExpanded(true);

      //
      VBox root= new VBox();
      root.setPadding(new Insets(5));
      root.getChildren().add(titledPane);
   
      Scene scene = new Scene(root, 250, 200);

      stage.setTitle("TitledPane (o7planning.org)");
      stage.setScene(scene);
      stage.show();
  }

}
Chạy ví dụ:

Xem thêm các chuyên mục: