1、Scene:創建場景
2、Stage:創建舞臺
4、stackPane:面板,節點放置在面板中央
5、FlowPane:節點以一行一行,或一列一列放置
6、GridPane:節點放置在一個二維網絡的單元格中
7、BorderPane:節點放置在四周及中央
8、HBox:節點放置在單行中
9、VBox:節點放置在單列中
10、Color:定義顏色
11、Font:定義字體大小,格式,粗細等
12、Image:獲取圖像
13、ImageView:按要求顯示圖像
14、Text:創建文本
15、Line:創建直線
16、Rectangle:創建矩形
17、Circle:創建圓
18、Ellipse:創建橢圓
19、Arc:創建弧
20、Polyogn: 創建封口的多邊形
21、Polyline:創建未封口的多邊形
eg:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Polyline;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class shape extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane pane = new BorderPane();
Pane paneTop = new Pane();
GridPane paneRight = new GridPane();
HBox paneLeft = new HBox();
StackPane paneCenter = new StackPane();
VBox paneBottom = new VBox();
Circle circle1 = new Circle(100, 100, 50);
Circle circle2 = new Circle(100, 100, 50);//一個圓只能添加進一個面板中,要兩個面板都顯示圓這要創建兩個圓
Circle circle3 = new Circle(100, 100, 50);
Line line = new Line(10, 10, 100, 100);
Rectangle r1 = new Rectangle(100, 100);//只定義長,寬
Rectangle r2 = new Rectangle(200, 50);
r2.setFill(Color.color(0, 0, 1, 0.3));
Ellipse e = new Ellipse(100, 50);
e.setFill(Color.WHITE);
e.setStroke(Color.BLUE);
Arc arc = new Arc(1000, 100, 100, 50, 0, 90);
Polygon p1 = new Polygon(200, 100, 200, 200, 10, 30, 320, 23);
p1.setStroke(Color.RED);
p1.setFill(Color.WHITE);
Polyline p2 = new Polyline(200, 100, 200, 200, 10, 30, 320, 23);
paneTop.getChildren().add(circle1);
paneTop.setStyle("-fx-border-color: red");//定義邊框顏色
paneTop.setPadding(new Insets(10, 10, 10, 10));//定義面板四周空餘的部分
paneRight.add(circle2, 0, 0);
paneRight.add(r1, 1, 1);
paneRight.setStyle("-fx-border-color: blue");
paneLeft.getChildren().add(line);
paneLeft.getChildren().add(circle3);//圓的座標可以沒有
paneLeft.setStyle("-fx-border-color: green");
paneBottom.getChildren().add(arc);
paneBottom.getChildren().add(p1);
paneBottom.getChildren().add(p2);
paneBottom.setStyle("-fx-border-color: orange");
paneCenter.getChildren().add(e);
paneCenter.getChildren().add(r2);
pane.setTop(paneTop);
pane.setRight(paneRight);
pane.setLeft(paneLeft);
pane.setCenter(paneCenter);
pane.setBottom(paneBottom);
Scene scnen = new Scene(pane);
primaryStage.setTitle("12");
primaryStage.setScene(scnen);
primaryStage.show();
}
public static void main(String[] args){
Application.launch(args);
}
}
顯示的圖像爲:
22、Button:創建一個按鈕
23、Label:創建一個標籤
24、RadioButton:創建一個單選按鈕
25、ToggleButton:創建一個開關按鈕
26、CheckBox:創建一個複選框,及是否打鉤
27、ChoiceBox:創建一個選擇框
28、TextField:創建一個文本框
29、PasswordField:創建一個密碼框
30、ScrollBar:創建一個滾動條
31、ColorPicker:創建一個顏色選擇器
32、DatePicker:創建一個時間選擇器
33、Separator:創建一個分隔符
34、Slider:創建一個滑塊
35、ProgressBar:創建一個進度條
36、ProgressIndicator:創建一個指示器,等待器
37、Hyperlink:創建一個超鏈接
38、HTMLEditor:創建一個HTML編譯器
39、Pagination:創建一個分頁控件
詳細請查看網站:http://www.javafxchina.net/blog/docs/tutorial3/
eg:
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.FlowPane;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;
public class UI2 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FlowPane pane = new FlowPane();
pane.setPadding(new Insets(10, 10, 10, 10));//定義面板四周空白部分距離節點的距離
pane.setOrientation(Orientation.VERTICAL);//定義節點的排列方式
pane.setHgap(50);//定義兩個節點之間的水平距離
pane.setVgap(20);//定義兩個節點之間的豎直距離
Button bt = new Button("1");//普通按鈕
Label lb = new Label("2");//標籤
RadioButton rb = new RadioButton("3");//單選按鈕
ToggleButton tb = new ToggleButton("4");//複選按鈕
CheckBox cb = new CheckBox("5");//複選框
ChoiceBox cob = new ChoiceBox(FXCollections.observableArrayList("a", "b", "c"));//選擇框
TextField tf = new TextField();//文本框
PasswordField pf = new PasswordField();//密碼文本框
ScrollBar sb = new ScrollBar();//進度條
ColorPicker cp = new ColorPicker();//顏色選擇器
DatePicker dp = new DatePicker();//時間選擇器
Separator sp = new Separator();//分隔符
Slider sd = new Slider();//滑塊
ProgressBar pb = new ProgressBar();//進度條
ProgressIndicator pi = new ProgressIndicator();//指示器,等待器
Hyperlink hk = new Hyperlink("http://www.javafxchina.net/blog/docs/tutorial3/");//超鏈接
HTMLEditor he = new HTMLEditor();//HTML編譯器
Pagination pt = new Pagination();//分頁控件
pane.getChildren().addAll(bt, lb, rb, tb, cb, cob, tf, pf, sb, cp,
dp, sp, sd, pb, pi, hk, he, pt);
Scene scene = new Scene(pane);
primaryStage.setTitle("UI");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args){
Application.launch(args);
}
}
運行結果如下圖: