1:group的功能
- group可以管理一組節點
- group可以對管理的節點進行增刪改查的操作
- group可以管理節點的屬性
1.2:看看jdkse1.9的api
group類有下列可以調用的方法
2:group的使用
代碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package application; import javafx.application.application; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.control.button; import javafx.stage.stage; public class main extends application { @override public void start(stage primarystage) throws exception { //創建button類 //注意:group容器組會自適應調節node節點的高、寬 以容納node節點的內容 例如:如果下面button的text內容比較多 那么對應的button會相應加長 button b1 = new button( "button1" ); b1.setlayoutx( 10 ); //設置起始點的x軸坐標 b1.setlayouty( 10 ); //設置起始的y軸坐標 //設置button的寬度 高度 b1.setprefwidth( 100 ); b1.setprefheight( 100 ); button b2 = new button( "button2" ); b2.setlayoutx( 100 ); b2.setlayouty( 10 ); button b3 = new button( "button3" ); b3.setlayoutx( 200 ); b3.setlayouty( 10 ); //創建group容器組 group group = new group(); group.getchildren().addall(b1 , b2 , b3); //創建場景scene scene scene = new scene(group); primarystage.setscene(scene); //設置stage的寬度 高度 primarystage.setheight( 500 ); primarystage.setwidth( 500 ); primarystage.show(); } public static void main(string[] args) { launch(args); } } |
運行結果:
2.1:添加node節點到group容器
1
2
3
|
//創建group容器組 group group = new group(); group.getchildren().addall(b1 , b2 , b3); |
2.2:刪除節點
1
2
3
4
5
6
|
//創建group容器組 group group = new group(); group.getchildren().addall(b1 , b2 , b3); //移除index為1的節點 也就是移除第二個node group.getchildren().remove( 1 ); |
以上所述是小編給大家介紹的javafx桌面應用開發-group(容器組)詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:https://blog.csdn.net/hujyhfwfh2/article/details/89059945