gpt4 book ai didi

java - JavaFX 中的虚线穿过实线

转载 作者:行者123 更新时间:2023-12-02 02:39:14 24 4
gpt4 key购买 nike

在 JavaFX 程序中,我绘制了一条黑色的单像素虚线。当我绘制黑色的单像素时在它上面的实线我仍然可以看到虚线穿过实线。无论我在 Canvas 上描画线条,还是使用设置了平滑的线条节点,都会发生这种情况为真。

这是为什么呢?有办法阻止吗?

附有示例程序和图像。

enter image description here

package sandbox2;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

public class Test extends Application
{
public static void main( String[] args )
{
launch( args );
}

@Override
public void start( Stage primaryStage ) throws Exception
{
primaryStage.setTitle( "Fx Playground" );

Group root = new Group();
Scene scene = new Scene( root, 350, 100 );
primaryStage.setScene( scene );

Line line1 = new Line( 50, 50, 300, 50 );
line1.setStroke( Color.BLACK );
line1.getStrokeDashArray().addAll( 5. );
line1.setSmooth( true );

Line line2 = new Line( 50, 50, 300, 50 );
line2.setStroke( Color.BLACK );
line2.setSmooth( true );

ObservableList<Node> nodes = root.getChildren();
nodes.add( line1 );
nodes.add( line2 );

primaryStage.show();
}

}

最佳答案

您应该将行构造函数更改为 new Line( 50.5, 50.5, 300, 50 ) 我认为这可以解决问题。有关说明,请参阅:https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Shape.html

关于java - JavaFX 中的虚线穿过实线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45762673/

24 4 0
文章推荐: java - Textview 文本颜色无法以编程方式工作
文章推荐: 滚动平方根和其他功能
文章推荐: javascript - 使用 中的 SVG 是否允许点击事件传播到父处理程序?