简体   繁体   English

如何在JavaFX中正确显示此特定形状的路径?

[英]How can I properly display this specific shape path in JavaFX?

Firstly, I'm a beginner in JavaFX coding. 首先,我是JavaFX编码的初学者。 Here, I'm actually trying to implement the Material Design checkbox as you can see right here , and using the API's default CheckBox for testing, here's what I currently have: 在这里,我实际上是在尝试实现Material Design复选框,正如您在此处看到的那样,并使用API​​的默认CheckBox进行测试,这是我目前拥有的:

Overriding CheckBox 's shape: 覆盖CheckBox的形状:

.check-box > .box > .mark {
  /* SVG path directly copied from the site. */
  -fx-shape: "M1.73,12.91 8.1,19.28 22.79,4.59";
}

Resulting to this: 结果:

So basically, I just copied the SVG path used by the MD checkbox component from here but it's not properly displayed as what the image above portrays in my case. 因此,基本上,我只是从此处复制了MD复选框组件所使用的SVG路径,但是由于我的情况,上面的图像无法正确显示该路径。 All I knew is the basics about SVG paths but drawing such complicated paths like the one I'm referring above is difficult for me. 我所知道的只是关于SVG路径的基础知识,但是绘制像我上面提到的那样的复杂路径对我来说很困难。

Now, my question is how can I fix this one? 现在,我的问题是如何解决这个问题? Thanks for all the answers. 感谢所有的答案。


UPDATE UPDATE

For others who were curious about what @Itai's provided shape path looks like, here it is: 对于其他对@Itai提供的形状路径感到好奇的人,这里是:

The path given in -fx-shape is the shape of the region, and is implicitly closed (last point connected to first) - this explains the result you are seeing, where the top right corner is connected back to the top left to create a triangle. -fx-shape给出的路径是该区域的形状,并且是隐式闭合的(最后一点连接到第一个点)-这解释了您看到的结果,在该结果中,右上角被连接回左上角以创建一个三角形。

You may be able to use this exact path using an SVGPath node, as in this question: How to style a SVG using CSS in javaFX FXML 您可以通过SVGPath节点使用此确切路径,如以下问题所示: 如何在javaFX FXML中使用CSS设置SVG的样式

Another possibility is to "transform" the path to the outline of the shape you want - by retracing the points in reverse order with slightly higher (or lower) Y values: 另一种可能性是将路径“转换”为所需形状的轮廓-通过以稍高(或低)的Y值以相反的顺序来跟踪点:

.check-box > .box > .mark {
    /* SVG path directly copied from the site. */
    -fx-shape: "M1.73,12.91 8.1,19.28 22.79,4.59 22.79,1.59 8.1,16.28 1.73,9.91";
}

In this case I have subtracted 3 from the Y values of every point and repeated them in reverse order, so get the original shape, 3 pixels wide. 在这种情况下,我从每个点的Y值中减去了3,并以相反的顺序重复了它们,因此获得了3像素宽的原始形状。 Note that this very basic transformation doesn't simulate any "miter" or "joint" effect, but it works in a pinch. 请注意,此非常基本的转换不会模拟任何“斜交”或“关节”效果,但可以在紧要关头工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM