繁体   English   中英

JavaFX HBox边框

[英]JavaFX HBox Border

我不明白为什么我的HBox周围没有边框? 由于我猜测this.setCenter(hbox)部分,除了Eclipse抛出IllegalArgumentException外,现在什么都没有发生。 (忽略此内容,我只是在写,因为StackOverflow不允许我上传此数量的代码)

package view;

import javafx.scene.paint.Color;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;

public class MyPane extends BorderPane{

private int score=0;

public MyPane() {
    this.score=0;
    init();
    // TODO Auto-generated constructor stub
}

public MyPane(int score) {
    this.score=score;
    init();
}

public void init() {

    Image img=new Image("Ball.png");
    ImageView imv= new ImageView(img);
    imv.setFitHeight(100);
    imv.setFitWidth(100);
    Label label= new Label(Integer.toString(score));
    label.setPrefSize(100, 100);
    label.setFont(new Font(50));
    label.setPadding(new Insets(18));



    HBox hbox= new HBox();
    hbox.setBorder(new Border(new BorderStroke(Color.GREEN, BorderStrokeStyle.SOLID, null , null)));
    hbox.getChildren().add(imv);
    hbox.getChildren().add(label);
    hbox.setSpacing(50);
    hbox.setPadding(new Insets(20));






    this.getChildren().add(hbox);
    this.setCenter(hbox);
}

}

您试图将HBox添加为BorderPane的“非托管”子级。 使用BorderPane ,必须指定要将Node放置在哪个区域

因此,问题不在于您的边框没有显示在HBox ,而是您的HBox从未真正添加到BorderPane

将您的最后一行更改为:

this.setCenter(hbox);

这会将您的HBox设置在BorderPane的中心。

请查看BorderPane文档以获取更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM