我正在制作一个JavaFX程序,旨在让人们制作游戏图(用于运动)。我需要这个程序才能拍摄图表的快照。我有奇怪的行为,快照似乎做了我需要的所有事情,除了标签没有出现在快照中。
I need a snapshot of this diagram
但是当我拍摄快照并尝试将其用作缩略图时,所有字母标签都丢失了。
奇怪的是,标签是堆叠窗格的一部分,堆叠窗格包含圆圈,它们仍然出现。我只是不明白为什么标签也没有出现。
此外,我确实找到了一个全面的工作。如果我无法弄清楚为什么标签没有出现在快照中,我发现我只是将Label更改为Text对象而不是......突然......快照工作正常!?!?
此时我只是将标签更改为文本对象,但它一直困扰我为什么它不能与标签一起使用。有人知道为什么会出现这种情况吗?
以下是包含标签的对象的代码。它从stackpane延伸。相关对象是“labelLbl”。再一次,简单地将其更改为Text似乎可以解决我的问题。
public class EditorPlayer extends StackPane {
private static final Image LEFT_SHADE_IMAGE = new Image(EditorPlayer.class.getClassLoader().getResourceAsStream("resources/leftshade.png"));
private static final Image MIDDLE_SHADE_IMAGE = new Image(EditorPlayer.class.getClassLoader().getResourceAsStream("resources/middleshade.png"));
private static final Image RIGHT_SHADE_IMAGE = new Image(EditorPlayer.class.getClassLoader().getResourceAsStream("resources/rightshade.png"));
//player we are wrapping
private Player player;
//parts of the editor player
private Shape shape;
private Label labelLbl;
private ObservableList<EditorPlayerAction> editorPlayerActions;
private FieldEditor fieldEditor;
private double radius;
private DoubleProperty editorX = new SimpleDoubleProperty(this, "editorX", 0);
private DoubleProperty editorY = new SimpleDoubleProperty(this, "editorY", 0);
private BooleanProperty selected = new SimpleBooleanProperty(this, "selected", false);
private double originalX, originalY, clickX, clickY;//need these values to perform drag
public void setSizes(double radius, double offFontSize, double defFontSize) {
this.radius = radius;
//create new components to reflect the resize
this.getChildren().clear();
if (this.getPlayer().getPlayerSide() == PlayerSide.OFFENSE) {
shape = new Circle(radius);
shape.setStrokeWidth(2);
shape.setStroke(Color.BLACK);
shape.setFill(Color.WHITE);
updateShadeGraphic();
} else {
shape = new Rectangle(radius * 2, radius * 2);
shape.setStrokeWidth(2);
shape.setStroke(Color.TRANSPARENT);
shape.setFill(Color.WHITE);
}
labelLbl = new Label(player.getLabel());
if (this.getPlayer().getPlayerSide() == PlayerSide.OFFENSE) {
labelLbl.setFont(Font.font("Helveitca", FontWeight.BOLD, offFontSize));
} else {
labelLbl.setFont(Font.font("Helveitca", FontWeight.BOLD, defFontSize));
}
this.getChildren().addAll(shape, labelLbl);
}
public void setOtherBehaviors(){
selected.addListener((selectedProperty, oldValue, newValue) -> {
if (newValue) {
if (this.getPlayer().getPlayerSide() == PlayerSide.OFFENSE) {
shape.setStrokeWidth(3);
shape.setStroke(Color.RED);
}
labelLbl.setTextFill(Color.RED);
fieldEditor.getSelectedPlayers().add(this);
} else {
if (this.getPlayer().getPlayerSide() == PlayerSide.OFFENSE) {
shape.setStrokeWidth(2);
shape.setStroke(Color.BLACK);
}
labelLbl.setTextFill(Color.BLACK);
fieldEditor.getSelectedPlayers().remove(this);
}
});
}