我有一个显示在我的JavaFX应用程序上的图像.给定坐标,我必须使用矩形在图像上显示该部分.例如,如果图像上有文本字段并且我给出了文本字段的坐标,则图像上的文本字段上应显示一个矩形(就像突出显示它一样).绘制矩形很容易,但我很难将其定位在图像上.请帮忙.
您应该使用不自动布局其子项的父组件.为此您可以使用Pane:
@Override
public void start( final Stage primaryStage )
{
ImageView imageView = new ImageView( ... );
// Optional: locating the image at iX-iY
// imageView.setX( iX );
// imageView.setY( iY );
Rectangle r = new Rectangle( rX, rY, width, height );
// Add rectangle at the last, so it shows up on the top of other children
Pane pane = new Pane( imageView, r );
final Scene scene = new Scene( pane, 400, 300 );
primaryStage.setScene( scene );
primaryStage.show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2290 次 |
| 最近记录: |