該当のソースコード
java
1import javafx.application.Application; 2import javafx.stage.Stage; 3import javafx.scene.Scene; 4import javafx.scene.layout.AnchorPane; 5import javafx.event.EventHandler; 6import javafx.animation.Timeline; 7import javafx.event.ActionEvent; 8import javafx.util.Duration; 9import javafx.animation.KeyFrame; 10import javafx.scene.layout.BorderPane; 11import javafx.scene.paint.Color; 12import javafx.scene.shape.Rectangle; 13 14 15public class DrawBall extends Application{ 16 17 public void start(Stage stage){ 18 stage.setHeight(600); 19 stage.setWidth(800); 20 stage.setMaximized(true); 21 22 BorderPane root = new BorderPane(); 23 AnchorPane center = new AnchorPane(); 24 AnchorPane drawPane = new AnchorPane(); //図形の描画領域 25 AnchorPane operatePane = new AnchorPane(); //操作領域 26 root.setCenter(center); 27 28 drawPane.setLayoutX(0); 29 drawPane.setLayoutY(0); 30 operatePane.setLayoutY(0); 31 center.getChildren().addAll(drawPane,operatePane); 32 33 34 stage.setScene(new Scene(root)); 35 stage.show(); 36 37 //操作領域の背景設定 38 Rectangle b = new Rectangle(0,0,2000,2000); 39 b.setFill(Color.rgb(220,220,220)); 40 operatePane.getChildren().add(b); 41 42 43 44 //操作領域と描画領域のバランス設定をリアルタイムで。 45 Timeline timeline = new Timeline( 46 new KeyFrame(Duration.millis(10), 47 new EventHandler<ActionEvent>(){ 48 public void handle(ActionEvent event){ 49 double x = stage.getWidth(); 50 double y = stage.getHeight(); 51 double cx; 52 cx = x*7/10; 53 drawPane.setPrefWidth(cx); 54 drawPane.setPrefHeight(y); 55 operatePane.setLayoutX(cx); 56 cx = x*3/10; 57 operatePane.setPrefWidth(cx); 58 operatePane.setPrefHeight(y); 59 60 } 61 })); 62 timeline.setCycleCount(Timeline.INDEFINITE); 63 timeline.play(); 64 } 65} 66 67
質問したいこと
上記のソースコードのように
ウィンドウの大きさを変更すると、埋め込まれている2つのAnchorPaneの大きさと位置を
7:3の大きさで維持するように変更される
ということを実現させたいです。
上記のコードではタイムラインを使って実装しているのですが
他の方法はないでしょうか?

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/17 04:26