【发布时间】:2013-07-16 09:42:58
【问题描述】:
我想在窗格中添加一行,但运行应用程序时未显示该行。 在我的窗格中添加带有 ImageView 的标签正在工作,我可以看到我在 ImageView 上设置的图像。我尝试以多种方式显示一条线,使用画布,绘制一条线并将画布添加到窗格中,还构建一条线并将其直接添加到窗格中,没有一个有效。
Pane pane = new Pane();
//Image image = new Image("image.png");
//ImageView imageView = new ImageView();
//imageView.setImage(image);
//Label label = new Label();
//label.setGraphic(imageView);
//Canvas canvas = new Canvas(105, 105);
//canvas.relocate(296, 128);
//GraphicsContext gc = canvas.getGraphicsContext2D();
//gc.setStroke(Color.BLUE);
//gc.setLineWidth(5);
//gc.strokeLine(0, 0, canvas.getWidth(), canvas.getHeight());
Line redLine = LineBuilder.create()
.startX(296)
.startY(128)
.endX(401)
.endY(233)
.fill(Color.RED)
.strokeWidth(10.0f)
.build();
pane.getChildren().add(redLine);
//pane.getChildren().add(canvas);
//pane.getChildren().addAll(label, redLine);
【问题讨论】:
-
“不工作”是什么意思?当我复制粘贴您的代码时,它对我有用(显示了一条线,虽然是一条黑色的)
-
是的,我的背景是黑色的,这就是为什么我没有看到这条线。必须设置属性 stroke 才能用想要的颜色绘制线条。