如何在JavaFX中创建SplitPane?
以下示例演示了SplitPane的创建。
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SplitPaneExample extends Application {
public void start(Stage stage) throws FileNotFoundException {
//Creating ImageView object1
Image img1 = new Image(new FileInputStream("D:\\images\\elephant.jpg"));
ImageView view1 = new ImageView(img1);
view1.setFitWidth(250);
view1.setFitHeight(150);
//Creating ImageView object2
Image img2 = new Image(new FileInputStream("D:\\images\\boy.jpg"));
ImageView view2 = new ImageView(img2);
view2.setFitWidth(250);
view2.setFitHeight(150);
//Creating a SplitPane
SplitPane splitPane = new SplitPane();
//Creating stack panes holding the ImageView objects
StackPane stackPane1 = new StackPane(view1);
StackPane stackPane2 = new StackPane(view2);
//Adding the stackpanes to the splitpane
splitPane.getItems().addAll(stackPane1, stackPane2);
//Setting anchor pane as the layout
AnchorPane pane = new AnchorPane();
AnchorPane.setTopAnchor(splitPane, 15.0);
AnchorPane.setRightAnchor(splitPane, 15.0);
AnchorPane.setBottomAnchor(splitPane, 15.0);
AnchorPane.setLeftAnchor(splitPane, 15.0);
pane.getChildren().addAll(splitPane);
pane.setStyle("-fx-background-color: BEIGE");
//Setting the stage
Scene scene = new Scene(pane, 595, 300);
stage.setTitle("Split Pane");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短