国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

JavaFX TitledPane

2018-01-09 19:24 更新

JavaFX教程 - JavaFX TitledPane


標題窗格是具有標題的面板,窗格可以打開和關閉。我們可以添加Node(如UI控件或圖像)和一組元素到窗格。

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
//from  w w w . j  a v  a 2 s  .  c o m
public class Main extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage stage) {
    Scene scene = new Scene(new Group(), 350, 250);
    TitledPane titledPane = new TitledPane("My Title", new CheckBox("OK"));

    HBox hbox = new HBox(10);
    hbox.setPadding(new Insets(20, 0, 0, 20));
    hbox.getChildren().setAll(titledPane);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
  }
}

上面的代碼生成以下結果。

null


創(chuàng)建標題窗格

要創(chuàng)建一個TitledPane控件,請調用其構造函數(shù)。

以下代碼使用TitledPane的雙參數(shù)構造函數(shù)。它將標題窗格命名為“我的窗格",并用一個Button控件填充窗格。

TitledPane tp = new TitledPane("My Pane", new Button("Button"));

接下來的幾行做了與上面的代碼相同的事情,而沒有使用構造函數(shù)帶參數(shù)。 它創(chuàng)建一個帶有默認空構造函數(shù)的TittedPane并設置標題并進行內容控制。

TitledPane tp = new TitledPane();
tp.setText("My Titled Pane");
tp.setContent(new Button("Button"));

以下代碼使用GridPane在TitledPane中布局控件。

TitledPane gridTitlePane = new TitledPane();
GridPane grid = new GridPane();
grid.setVgap(4);
grid.setPadding(new Insets(5, 5, 5, 5));
...
gridTitlePane.setText("Grid");
gridTitlePane.setContent(grid);

我們可以定義標題窗格的打開和關閉方式。默認情況下,所有標題窗格都是可折疊的,打開和關閉操作都是動畫。

setCollapsible(false)關閉Collapsible狀態(tài)。setAnimated(false)停止動畫。

TitledPane tp = new TitledPane();
tp.setCollapsible(false);//remove closing action
tp.setAnimated(false);//stop animating

完整的源代碼

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
/*from   ww w . j a  v a 2s  .  c  o  m*/
public class Main extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage stage) {
    Scene scene = new Scene(new Group(), 450, 250);
    TitledPane titledPane = new TitledPane("My Title", new CheckBox("OK"));
    titledPane.setCollapsible(false);//remove closing action
    titledPane.setAnimated(false);//stop animating
    
    HBox hbox = new HBox(10);
    hbox.setPadding(new Insets(20, 0, 0, 20));
    hbox.getChildren().setAll(titledPane);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
  }
}

上面的代碼生成以下結果。

null


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號