在我想画一个三角形控件的大小,并有三角形自定义控件的皮肤成长为帧大小。我有以下代码,但边界只是在调整框架大小时增加。如何让它正确调整大小?在javafx 2.0中获取给定布局中节点的大小?
private void update()
{
Bounds bounds = node.getBoundsInParent();
Path path = new Path();
path.getElements().add(
new MoveTo(
bounds.getWidth()/2 + bounds.getMinX(),
bounds.getMinY()));
path.getElements().add(
new LineTo(bounds.getMaxX(), bounds.getMaxY()));
path.getElements().add(
new LineTo(bounds.getMinX(), bounds.getMaxY()));
path.setFill(Color.RED);
node.getChildren().setAll(path);
}
编辑:使用摆动我会做以下事情。但是我无法在JavaFX中使用它。
public class Arrow extends JPanel
{
@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
Dimension size = getSize();
Point top = new Point(size.width/2,0);
Point bottomRight = new Point(size.width, size.height);
Point bottomLeft = new Point(0, size.height);
GeneralPath path = new GeneralPath();
path.moveTo(top.x, top.y);
path.lineTo(bottomRight.x, bottomRight.y);
path.lineTo(bottomLeft.x, bottomLeft.y);
path.lineTo(top.x, top.y);
Graphics2D g2d = (Graphics2D)graphics.create();
g2d.setColor(Color.RED);
g2d.fill(path);
g2d.dispose();
}
}
我不能有什么不对“边界大小为我调整框架只会增加”? –