下面列出了javafx.scene.control.Label#setLayoutX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void start(Stage stage) {
Pane root = new Pane();
for(int i = 0 ;i < 4000; i++) {
Label child = new Label("label" + i);
child.setLayoutX(Math.random() * 500 + 100);
child.setLayoutY(Math.random() * 500+ 100);
root.getChildren().add(child);
}
root.getChildren().add(build());
FPSDecorator decorator = new FPSDecorator(stage, root);
final Scene scene = new Scene(decorator, 800, 800);
stage.setScene(scene);
stage.setResizable(true);
stage.show();
afterShow(stage);
}
public MyNode(String name) {
text = new Label(name);
text.setStyle("-fx-border-color:black; -fx-padding:3px;");
text.setLayoutX(4);
text.setLayoutY(2);
getChildren().addAll(text);
}
public MyNode(String name) {
text = new Label(name);
text.setStyle("-fx-border-color:black; -fx-padding:3px;");
text.setLayoutX(4);
text.setLayoutY(2);
getChildren().addAll(text);
}
@Override
public void autocalibrationTimedOut() {
calibrated = false;
final Label calibrationLabel = new Label("Calibration Failed!");
calibrationLabel.setFont(Font.font(48));
calibrationLabel.setTextFill(Color.web("#f5a807"));
calibrationLabel.setLayoutX(6);
calibrationLabel.setLayoutY(6);
calibrationLabel.setPrefSize(628, 90);
calibrationLabel.setAlignment(Pos.CENTER);
arenaPane.getCanvasManager().getCanvasGroup().getChildren().add(calibrationLabel);
}
public TextFieldWithIcon() {
textField = new JFXTextField();
textField.setEditable(false);
textField.setMouseTransparent(true);
textField.setFocusTraversable(false);
setLeftAnchor(textField, 0d);
setRightAnchor(textField, 0d);
dummyTextField = new Label();
dummyTextField.setWrapText(true);
dummyTextField.setAlignment(Pos.CENTER_LEFT);
dummyTextField.setTextAlignment(TextAlignment.LEFT);
dummyTextField.setMouseTransparent(true);
dummyTextField.setFocusTraversable(false);
setLeftAnchor(dummyTextField, 0d);
dummyTextField.setVisible(false);
iconLabel = new Label();
iconLabel.setLayoutX(0);
iconLabel.setLayoutY(3);
dummyTextField.widthProperty().addListener((observable, oldValue, newValue) -> {
iconLabel.setLayoutX(dummyTextField.widthProperty().get() + 20);
});
getChildren().addAll(textField, dummyTextField, iconLabel);
}
private void initComponent() {
this.setWidth(520);
this.setHeight(120);
this.setResizable(false);
this.setTitlePaneStyle(2);
this.setRadius(5);
this.setCenter(rootPane);
this.setTitle("服务器地址设置");
titleLabel.setText("服务器地址设置");
titleLabel.setFont(Font.font("微软雅黑", 14));
titleLabel.setStyle("-fx-text-fill:rgba(255, 255, 255, 1)");
topBox.setStyle("-fx-background-color:#2cb1e0");
topBox.setPrefHeight(35);
topBox.setPadding(new Insets(5, 10, 5, 10));
topBox.setSpacing(10);
topBox.getChildren().add(titleLabel);
Label addressLabel = new Label("服务器地址:");
addressField.setPromptText("服务器地址");
addressLabel.setPrefSize(75, 25);
addressLabel.setLayoutX(10);
addressLabel.setLayoutY(5);
addressField.setPrefSize(250, 25);
addressField.setLayoutX(addressLabel.getLayoutX() + addressLabel.getPrefWidth() + 10);
addressField.setLayoutY(addressLabel.getLayoutY());
portField.setPromptText("端口");
Label partLabel = new Label("端口:");
partLabel.setPrefSize(40, 25);
partLabel.setLayoutX(355);
partLabel.setLayoutY(5);
portField.setPrefSize(80, 25);
portField.setLayoutX(partLabel.getLayoutX() + partLabel.getPrefWidth() + 10);
portField.setLayoutY(partLabel.getLayoutY());
AnchorPane infoPane = new AnchorPane();
infoPane.setStyle("-fx-background-color:#ffffff");
infoPane.getChildren().add(addressLabel);
infoPane.getChildren().add(addressField);
infoPane.getChildren().add(partLabel);
infoPane.getChildren().add(portField);
cancelButton.setText("取消");
cancelButton.setPrefWidth(80);
button.setText("确定");
button.setPrefWidth(80);
bottomBox.setStyle("-fx-background-color:#c9e1e9");
bottomBox.setAlignment(Pos.BASELINE_RIGHT);
bottomBox.setPadding(new Insets(5, 10, 5, 10));
bottomBox.setSpacing(10);
bottomBox.getChildren().add(button);
bottomBox.getChildren().add(cancelButton);
rootPane.setTop(topBox);
rootPane.setCenter(infoPane);
rootPane.setBottom(bottomBox);
Pattern pattern = Pattern.compile("0|(-?([1-9]\\d*)?)");
;
TextFormatter<Integer> formatter = new TextFormatter<Integer>(new StringConverter<Integer>() {
@Override
public String toString(Integer value) {
return null != value ? value.toString() : "0";
}
@Override
public Integer fromString(String text) {
int i = 0;
if (null != text) {
Matcher matcher = pattern.matcher(text);
if (matcher.matches()) {
i = Integer.parseInt(text);
}
}
return i;
}
});
portField.setTextFormatter(formatter);
}
private void initComponent() {
this.setStyle("-fx-background-color:#ffffff");
upButton.setText("上一步");
button.setText("确定");
upButton.setPrefSize(80, 25);
button.setPrefSize(80, 25);
Label passwordLabel = new Label("新密码");
Label confirmPasswordLabel = new Label("确认密码");
passwordField.setPromptText("新密码");
confirmPasswordField.setPromptText("确认密码");
passwordLabel.setPrefSize(50, 25);
passwordLabel.setLayoutX(10);
passwordLabel.setLayoutY(15);
passwordField.setPrefSize(290, 25);
passwordField.setLayoutX(passwordLabel.getLayoutX() + passwordLabel.getPrefWidth() + 10);
passwordField.setLayoutY(passwordLabel.getLayoutY());
confirmPasswordLabel.setPrefSize(50, 25);
confirmPasswordLabel.setLayoutX(10);
confirmPasswordLabel.setLayoutY(passwordField.getLayoutY() + passwordField.getPrefHeight() + 15);
confirmPasswordField.setPrefSize(290, 25);
confirmPasswordField.setLayoutX(confirmPasswordLabel.getLayoutX() + confirmPasswordLabel.getPrefWidth() + 10);
confirmPasswordField.setLayoutY(confirmPasswordLabel.getLayoutY());
AnchorPane infoPane = new AnchorPane();
infoPane.getChildren().add(passwordLabel);
infoPane.getChildren().add(confirmPasswordLabel);
infoPane.getChildren().add(passwordField);
infoPane.getChildren().add(confirmPasswordField);
infoPane.setPrefHeight(confirmPasswordField.getLayoutY() + 50);
topVBox.getChildren().add(infoPane);
scrollPane.setBackground(Background.EMPTY);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setContent(box);
HBox bottomBox = new HBox();
bottomBox.setAlignment(Pos.CENTER);
bottomBox.setPadding(new Insets(5, 10, 5, 10));
bottomBox.setSpacing(10);
bottomBox.getChildren().add(upButton);
bottomBox.getChildren().add(button);
over.setContentNode(overLabel);
baseBorderPane.setTop(topVBox);
baseBorderPane.setCenter(scrollPane);
baseBorderPane.setBottom(bottomBox);
this.getChildren().add(baseBorderPane);
}
private void initComponent() {
this.setTitle("修改资料");
this.setResizable(false);
this.setTitlePaneStyle(2);
this.setWidth(390);
this.setHeight(520);
this.setRadius(5);
this.setCenter(rootPane);
Label nameLabel = new Label("名 \t 称");
Label introduceLabel = new Label("介 \t 绍");
Label publicNoticeLabel = new Label("公 \t 告");
nameField.setPromptText("名称");
introduceTextArea.setPromptText("介 绍");
publicNoticeTextArea.setPromptText("公 告");
imagePanel.setHeadSize(70);
imagePanel.setPrefSize(75, 75);
imagePanel.setLayoutX(70);
imagePanel.setLayoutY(20);
nameLabel.setPrefSize(50, 25);
nameLabel.setLayoutX(10);
nameLabel.setLayoutY(120);
nameField.setPrefSize(290, 25);
nameField.setLayoutX(nameLabel.getLayoutX() + nameLabel.getPrefWidth() + 10);
nameField.setLayoutY(nameLabel.getLayoutY());
introduceLabel.setPrefSize(50, 25);
introduceLabel.setLayoutX(10);
introduceLabel.setLayoutY(nameField.getLayoutY() + nameField.getPrefHeight() + 15);
introduceTextArea.setPrefSize(290, 120);
introduceTextArea.setLayoutX(nameField.getLayoutX());
introduceTextArea.setLayoutY(introduceLabel.getLayoutY());
publicNoticeLabel.setPrefSize(50, 25);
publicNoticeLabel.setLayoutX(10);
publicNoticeLabel.setLayoutY(introduceTextArea.getLayoutY() + introduceTextArea.getPrefHeight() + 15);
publicNoticeTextArea.setPrefSize(290, 120);
publicNoticeTextArea.setLayoutX(nameField.getLayoutX());
publicNoticeTextArea.setLayoutY(publicNoticeLabel.getLayoutY());
AnchorPane infoPane = new AnchorPane();
infoPane.setStyle("-fx-background-color:#ffffff");
infoPane.getChildren().add(nameLabel);
infoPane.getChildren().add(introduceLabel);
infoPane.getChildren().add(publicNoticeLabel);
infoPane.getChildren().add(nameField);
infoPane.getChildren().add(introduceTextArea);
infoPane.getChildren().add(publicNoticeTextArea);
cancelButton.setText("取消");
cancelButton.setPrefWidth(80);
button.setText("确定");
button.setPrefWidth(80);
bottomBox.setStyle("-fx-background-color:#c9e1e9");
bottomBox.setAlignment(Pos.BASELINE_RIGHT);
bottomBox.setPadding(new Insets(5, 10, 5, 10));
bottomBox.setSpacing(10);
bottomBox.getChildren().add(button);
bottomBox.getChildren().add(cancelButton);
//VBox vBox=new VBox();
infoPane.getChildren().add(imagePanel);
//vBox.getChildren().add(infoPane);
rootPane.setCenter(infoPane);
rootPane.setBottom(bottomBox);
}
private void initComponent() {
this.setWidth(420);
this.setHeight(120);
this.setResizable(false);
this.setTitlePaneStyle(2);
this.setRadius(5);
this.setCenter(rootPane);
this.setTitle("服务器地址设置");
Label nameLabel = new Label("服务器地址:");
addressField.setPromptText("服务器地址");
nameLabel.setPrefSize(75, 25);
nameLabel.setLayoutX(10);
nameLabel.setLayoutY(5);
addressField.setPrefSize(300, 25);
addressField.setLayoutX(nameLabel.getLayoutX() + nameLabel.getPrefWidth() + 10);
addressField.setLayoutY(nameLabel.getLayoutY());
AnchorPane infoPane = new AnchorPane();
infoPane.setStyle("-fx-background-color:#ffffff");
infoPane.getChildren().add(nameLabel);
infoPane.getChildren().add(addressField);
cancelButton.setText("取消");
cancelButton.setPrefWidth(80);
button.setText("确定");
button.setPrefWidth(80);
bottomBox.setStyle("-fx-background-color:#c9e1e9");
bottomBox.setAlignment(Pos.BASELINE_RIGHT);
bottomBox.setPadding(new Insets(5, 10, 5, 10));
bottomBox.setSpacing(10);
bottomBox.getChildren().add(button);
bottomBox.getChildren().add(cancelButton);
rootPane.setTop(topBox);
rootPane.setCenter(infoPane);
rootPane.setBottom(bottomBox);
}
public OverView() {
root = new Pane();
Game.getInstance().resetMedia();
GameMap map = Game.getInstance().getMapManager().getCurrentMap();
ImageView mapIv = new ImageView(map.getMapImage());
mapIv.setFitWidth(Game.getInstance().getWidth());
mapIv.setFitHeight(Game.getInstance().getHeight());
Label nameLbl = new Label("Game Over!");
nameLbl.setTextFill(Color.WHITESMOKE);
nameLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 80));
nameLbl.setLayoutX(50);
nameLbl.setLayoutY(50);
Label scoreLbl = new Label();
scoreLbl.setTextFill(Color.WHITESMOKE);
scoreLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 60));
scoreLbl.setLayoutX(50);
scoreLbl.setLayoutY(map.getHeight() - scoreLbl.getHeight() - 140);
if (Game.getInstance().getScore() > Game.getInstance().getDataManager().getHighestScore()) {
// 刷新高分记录!
scoreLbl.setText("New Record: " + Game.getInstance().getScore());
Game.getInstance().getDataManager().setHighestScore(Game.getInstance().getScore());
} else
scoreLbl.setText("Score: " + Game.getInstance().getScore());
Reflection reflection = new Reflection();
reflection.setFraction(1.0);
nameLbl.setEffect(reflection);
ImageView homeBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_home"));
homeBtn.setFitWidth(165 * 1.5);
homeBtn.setFitHeight(65 * 1.5);
homeBtn.setLayoutX(map.getWidth() - homeBtn.getFitWidth() - 20);
homeBtn.setLayoutY(map.getHeight() - homeBtn.getFitHeight() - 60);
homeBtn.setEffect(reflection);
homeBtn.setOnMouseEntered(event -> {
homeBtn.setEffect(new Glow(0.8));
Game.getInstance().getButtonOverMusic().play();
});
homeBtn.setOnMouseExited(event -> {
homeBtn.setEffect(reflection);
Game.getInstance().getButtonOverMusic().stop();
});
homeBtn.setOnMousePressed(event -> {
homeBtn.setEffect(new GaussianBlur());
Game.getInstance().getButtonClickMusic().play();
});
homeBtn.setOnMouseReleased(event -> {
homeBtn.setEffect(new Glow(0.8));
Game.getInstance().home();
});
root.getChildren().add(mapIv);
root.getChildren().add(nameLbl);
root.getChildren().add(scoreLbl);
root.getChildren().add(homeBtn);
makeFadeTransition(homeBtn, 2000, 1, 0.7);
makeFadeTransition(mapIv, 3000, 1, 0.8);
makeScaleTransition(mapIv, 10000, 0.25, 0.25);
}
public PauseView() {
root = new Pane();
Game.getInstance().resetMedia();
map = Game.getInstance().getMapManager().getCurrentMap();
mapIv = new ImageView(map.getMapImage());
mapIv.setFitWidth(Game.getInstance().getWidth());
mapIv.setFitHeight(Game.getInstance().getHeight());
nameLbl = new Label("CrazyAlpha!");
nameLbl.setTextFill(Color.WHITESMOKE);
nameLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 120));
nameLbl.setLayoutX(50);
nameLbl.setLayoutY(50);
Reflection reflection1 = new Reflection();
reflection1.setFraction(1.0);
nameLbl.setEffect(reflection1);
Reflection reflection02 = new Reflection();
reflection02.setFraction(0.4);
resumeBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_resume"));
resumeBtn.setFitWidth(165 * 1.5);
resumeBtn.setFitHeight(65 * 1.5);
exitBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_exit"));
exitBtn.setFitWidth(165 * 1.5);
exitBtn.setFitHeight(65 * 1.5);
resumeBtn.setLayoutX(map.getWidth() - resumeBtn.getFitWidth() - 20);
resumeBtn.setLayoutY(map.getHeight() - resumeBtn.getFitHeight() - exitBtn.getFitHeight() - 120);
resumeBtn.setEffect(reflection02);
resumeBtn.setOnMouseEntered(event -> {
resumeBtn.setEffect(new Glow(0.8));
Game.getInstance().getButtonOverMusic().play();
});
resumeBtn.setOnMouseExited(event -> {
resumeBtn.setEffect(reflection02);
Game.getInstance().getButtonClickMusic().stop();
});
resumeBtn.setOnMousePressed(event -> {
resumeBtn.setEffect(new GaussianBlur());
Game.getInstance().getButtonClickMusic().play();
Game.getInstance().resume();
});
resumeBtn.setOnMouseReleased(event -> {
resumeBtn.setEffect(new Glow(0.8));
});
exitBtn.setLayoutX(map.getWidth() - exitBtn.getFitWidth() - 20);
exitBtn.setLayoutY(map.getHeight() - exitBtn.getFitHeight() - 60);
exitBtn.setEffect(reflection02);
exitBtn.setOnMouseEntered(event -> {
exitBtn.setEffect(new Glow(0.8));
Game.getInstance().getButtonOverMusic().play();
});
exitBtn.setOnMouseExited(event -> {
exitBtn.setEffect(reflection02);
Game.getInstance().getButtonOverMusic().stop();
});
exitBtn.setOnMousePressed(event -> {
exitBtn.setEffect(new GaussianBlur());
Game.getInstance().getButtonClickMusic().play();
});
exitBtn.setOnMouseReleased(event -> {
exitBtn.setEffect(new Glow(0.8));
Game.getInstance().exit();
});
root.getChildren().add(mapIv);
root.getChildren().add(nameLbl);
root.getChildren().add(resumeBtn);
root.getChildren().add(exitBtn);
makeFadeTransition(resumeBtn, 2000, 1, 0.7);
makeFadeTransition(exitBtn, 2000, 1, 0.7);
makeFadeTransition(mapIv, 3000, 1, 0.8);
makeScaleTransition(mapIv, 10000, 0.25, 0.25);
}
@Override
public Scene createScene() {
GeometryNode<RoundedRectangle> end1 = new GeometryNode<>(
new RoundedRectangle(50, 50, 30, 30, 20, 20));
end1.setFill(Color.RED);
end1.setStrokeWidth(3);
end1.setStrokeType(StrokeType.OUTSIDE);
makeDraggable(end1);
// use a shape
javafx.scene.shape.Rectangle end2 = new javafx.scene.shape.Rectangle(
200, 50, 30, 30);
end2.setArcWidth(20);
end2.setArcHeight(20);
end2.setStroke(Color.BLACK);
end2.setFill(Color.RED);
end2.setStrokeWidth(3);
end2.setStrokeType(StrokeType.OUTSIDE);
makeDraggable(end2);
// use a control as start, where layout bounds are always (0, 0, width,
// height); this demonstrates anchor positions are calculated properly
Label start = new Label("Some label");
start.setLayoutX(150);
start.setLayoutY(150);
makeDraggable(start);
// start.setBackground(new Background(new BackgroundFill(Color.GREY,
// CornerRadii.EMPTY, new Insets(0))));
// start.setBorder(
// new Border(new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID,
// CornerRadii.EMPTY, new BorderWidths(10))));
// set start point and end anchor
// create connection, provide decoration
Connection connection1 = new Connection();
connection1.setEndDecoration(new ArrowHead());
connection1.setStartAnchor(new DynamicAnchor(start));
connection1.setEndAnchor(new DynamicAnchor(end1));
Connection connection2 = new Connection();
connection2.setRouter(new OrthogonalRouter());
connection2.setEndDecoration(new ArrowHead());
connection2.setStartAnchor(
new DynamicAnchor(start, new OrthogonalProjectionStrategy()));
connection2.setEndAnchor(
new DynamicAnchor(end2, new OrthogonalProjectionStrategy()));
Group root = new Group();
root.getChildren().addAll(start, end1, end2, connection1, connection2);
return new Scene(root, 300, 300);
}
public ProjectorArenaPane(Stage arenaStage, Stage shootOffStage, Pane trainingExerciseContainer, Resetter resetter,
ObservableList<ShotEntry> shotTimerModel) {
config = Configuration.getConfig();
arenaCanvasGroup = new Group();
calibrationLabel = new Label("Needs Calibration");
calibrationLabel.setFont(Font.font(48));
calibrationLabel.setTextFill(Color.web("#f5a807"));
calibrationLabel.setLayoutX(6);
calibrationLabel.setLayoutY(6);
calibrationLabel.setPrefSize(628, 90);
calibrationLabel.setAlignment(Pos.CENTER);
getChildren().addAll(arenaCanvasGroup, calibrationLabel);
this.shootOffStage = shootOffStage;
this.arenaStage = arenaStage;
this.trainingExerciseContainer = trainingExerciseContainer;
if (config.isHeadless()) {
canvasManager = new CanvasManager(arenaCanvasGroup, resetter, "arena", shotTimerModel);
} else {
canvasManager = new MirroredCanvasManager(arenaCanvasGroup, resetter, "arena", shotTimerModel, this);
}
setPrefSize(640, 480);
setOnKeyPressed((event) -> canvasKeyPressed(event));
setOnMouseEntered((event) -> requestFocus());
setOnMouseClicked((event) -> {
canvasManager.toggleTargetSelection(Optional.empty());
});
arenaStage.widthProperty().addListener((e) -> {
canvasManager.setBackgroundFit(arenaStage.getWidth(), arenaStage.getHeight());
});
arenaStage.heightProperty().addListener((e) -> {
canvasManager.setBackgroundFit(arenaStage.getWidth(), arenaStage.getHeight());
});
setStyle("-fx-background-color: #333333;");
}