这就是建议亚历山大·基洛夫 https://stackoverflow.com/users/1951882/alexander-kirov,如果我理解得好的话:
import javafx.application.Application;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polyline;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;
public class TransRotScal extends Application {
@Override
public void start( Stage primaryStage ) throws Exception {
Pane pane = new Pane();
pane.setScaleX( 10.0 );
pane.setScaleY( 10.0 );
pane.setRotate( theta );
pane.setTranslateX( 468.0 );
pane.setTranslateY( 152.0 );
Polyline line = new Polyline( 10,20, 10,30, 50,30, 50,35 );
line.setStroke( Color.DARKRED );
Circle c0 = new Circle( 10, 20, 2, Color.BLACK );
Circle c1 = new Circle( 10, 30, 2, Color.LIGHTSALMON );
Circle c2 = new Circle( 50, 30, 2, Color.LIGHTSALMON );
Circle c3 = new Circle( 50, 35, 2, Color.BLACK );
Text t0 = createText( 10, 20, "[10,20]", VPos.BOTTOM );
Text t1 = createText( 10, 30, "[10,30]", VPos.TOP );
Text t2 = createText( 50, 30, "[50,30]", VPos.BOTTOM );
Text t3 = createText( 50, 35, "[50,35]", VPos.TOP );
pane.getChildren().addAll( line, c0, c1, c2, c3, t0, t1, t2, t3 );
primaryStage.setScene( new Scene( pane ));
primaryStage.centerOnScreen();
primaryStage.setWidth ( 580 );
primaryStage.setHeight( 280 );
primaryStage.show();
}
private Text createText( int x, int y, String label, VPos vPos ) {
Text text = new Text( x, y, label );
text.setFill( Color.DARKGRAY );
text.setFont( Font.font( Font.getDefault().getFamily(), 1.4 ));
text.rotateProperty().set( -theta );
text.textAlignmentProperty().setValue( TextAlignment.CENTER );
text.setX( text.getX() - text.getBoundsInLocal().getWidth()/2.0);
text.textOriginProperty().set( vPos );
if( vPos == VPos.BOTTOM ) {
text.setY( text.getY() - 2 );
}
else {
text.setY( text.getY() + 2 );
}
return text;
}
private final double theta = Math.toDegrees( Math.atan2( -15.0, 40.0 ));
public static void main( String[] args ) {
launch();
}
}
它可以工作,但它使用 Node 代替画布,并且调整文本的值是通过迭代尝试获得的(很多!);我不知道如何计算它们.
亚历山大,您可以编辑这篇文章或发布您自己的文章来完成它,在后一种情况下我将删除它。
这是结果,请注意光盘周围文本的近似位置: