试图让Hbox位于父窗格

时间:2017-12-07 15:51:32

标签: java css javafx javafx-8

我一直试图将一个蓝色的盒子放在一个黑盒子里,简单地把它放进去。

我有一个名为DialoguePane的类,它扩展了Javafx Pane。它还有一个字段,一个应该保存名为actionButtonHBox的按钮的HBox,我想把它放在DialoguePane中。

下面是窗口的图片。带有“选择操作”标签的框是DialoguePane对象。现在,我已经把两个盒子放在彼此里面了。但是,当我尝试调用.setBackground方法或使用CSS样式来尝试设置Hbox的背景样式时,没有任何变化,背景不会改变。我也使用toFront(),但没有任何改变。我很高兴我至少可以将盒子放在彼此的内部,但我只是想改变这个区域的背景颜色以进行格式化和设计。

picture of javafx window

这是Dialogue Pane构造函数的相关部分

public class DialoguePane extends Pane {
     private HBox actionButtonHbox;
     public DialoguePane(String string) {
         super();
         this.resizeRelocate(480, 200, 450, 140); //Makes the DialoguePane's whole region have a width of 450, height of 140, at position x-cor 480px and y-cor 200px
         this.setStyle("-fx-background-color: rgba(0, 0, 0, .95)");
         //this.setDisplayableText(string);
         this.makeActionButtonHbox();
     }
     public void makeActionButtonHbox() {
         actionButtonHbox = new HBox();
         System.out.println("Before: " + actionButtonHbox.backgroundProperty());
         actionButtonHbox.resizeRelocate(0, 100, 400, 40); //Sets it at this position inside of the DialoguePane, a box with 400 width and 40 height. It's pretty thin.
         actionButtonHbox.setBackground(new Background(new BackgroundFill(Color.LIGHTBLUE, CornerRadii.EMPTY, Insets.EMPTY)));
         actionButtonHbox.toFront();
         System.out.println("After " + actionButtonHbox.backgroundProperty());
         this.getChildren().add(actionButtonHbox);
}

还有其他代码负责将TextArea放在hbox之上(这是在Pane中的“在下面选择一个动作”,这在setDisplayableText方法中发生)。

那么我该怎样做才能让这个窗格的背景可见?

0 个答案:

没有答案