这是我在javafx中的当前输出。
我想所有的标签和边框要齐平。
我所有的插图都是一样的,为什么所有的东西都不对齐呢?
另一个问题是双重重叠的边界创建一个较暗的图像上的边界,我不知道如何修复时,设置我的标签样式。下图是相关代码。谢谢您。
public void buildUI() {
HBox hbox = new HBox(); // create Hbox
hbox.setPadding(new Insets(20,20,40,215) ); // centers month name over Grid
Label month = new Label ("October"); // create october label
//hbox.setVgap(50.0);
this.setTop(hbox); // set hbox to top of borderPane
hbox.getChildren().addAll(month); // add month to hbox
this.setCenter(grid); // add gridPane to center of BorderPane
grid.setPadding(new Insets(20,20,20,20) ); // add insets to gridPane for aesthetic
// below makes S-M-T-W-T-F and green fill
for (int i = 0; i <= weekDays.length - 1; i++) {
Label daysOfWeek = new Label(weekDays[i]);
grid.add(daysOfWeek, i + 1, 1);
daysOfWeek.setPadding(new Insets(25,30,25,30) );
daysOfWeek.setStyle("-fx-text-fill: white;" +
"-fx-background-color: green;" + "-fx-border-color: black;");
}// end for loop to cycle through days of week
//below are the days of the month
for (int i = 1; i <= FRAMES; i++) {
int yPos = ((i - 1) / 7) + 2;
int xPos = i - (7 * (yPos -2) );
if (i < 32) {
Label monthDays = new Label(String.valueOf(i) );
grid.add(monthDays, xPos, yPos);
monthDays.setPadding(new Insets(25,30,25,30) );
monthDays.setStyle("-fx-border-color: black;");
} else if (i > 32) {
// below creating november labels days 1 -- 4
Label nov1 = new Label("1");
grid.add(nov1, 4, 6);
Label nov2 = new Label("2");
grid.add(nov2, 5, 6);
Label nov3 = new Label("3");
grid.add(nov3, 6, 6);
Label nov4 = new Label("4");
grid.add(nov4, 7, 6);
// below padding and making borders for labels
nov1.setPadding(new Insets(25,30,25,30) );
nov1.setStyle("-fx-text-fill: white;" + "-fx-border-color: black;" + "-fx-background-color: grey;");
nov2.setPadding(new Insets(25,30,25,30) );
nov2.setStyle("-fx-text-fill: white;" + "-fx-border-color: black;" + "-fx-background-color: grey;");
nov3.setPadding(new Insets(25,30,25,30) );
nov3.setStyle("-fx-text-fill: white;" + "-fx-border-color: black;" + "-fx-background-color: grey;");
nov4.setPadding(new Insets(25,30,25,30) );
nov4.setStyle("-fx-text-fill: white;" + "-fx-border-color: black;" + "-fx-background-color: grey;");
}
}// end for loop to cycle through days of month
}
1条答案
按热度按时间sg3maiej1#
Label
s的最大大小与文本和填充所需的大小相匹配。这个GridPane
不调整Label
一位数字填充该列所需的更大的大小。简单地将max size设置为无穷大就可以解决这个问题。
如果不绘制双边框,可以将边框大小(顶部和右侧)设置为1,底部和左侧设置为0,将
GridPane
使用底部和左侧宽度为1、顶部和右侧宽度为0的边框,并将网格以StackPane
对于填充: