This discussion is archived
6 Replies Latest reply: Nov 20, 2012 2:00 AM by fabsav RSS

How to realize alternative stroke types

MiPa Pro
Currently Being Moderated
Hi,
for a Swing project I had to realize some alternative stroke types like the ones shown in this image.

http://www.imgbox.de/users/public/images/3uciipVJzt.png

I am wondering how the same could be achieved with JavaFX. The problem is that JavaFX does not have a concept which is equivalent to the Swing Stroke.

Michael
  • 1. Re: How to realize alternative stroke types
    MiPa Pro
    Currently Being Moderated
    Nobody any idea how to do this?
  • 2. Re: How to realize alternative stroke types
    jsmith Guru
    Currently Being Moderated
    I have no idea MiPa - you always ask the trickiest questions which are usually the result of limitations in the JavaFX platform.
  • 3. Re: How to realize alternative stroke types
    shakir.gusaroff Expert
    Currently Being Moderated
    Hi Michael. It might not be the best approach. You can find a better solution.
    @Override
        public void start(Stage primaryStage) {
            Group root = new Group();
            for (int i = 0; i < 120; i++) {
                Polyline template = new Polyline();
                template.getPoints().addAll(new Double[]{0.0, 3.0, -3.0, -3.0, 3.0, -3.0});
                template.setTranslateX(100);
                template.setTranslateY(100);
                template.setStroke(Color.RED);
                template.getTransforms().add(new Rotate(i * 3, 120, 100));
                root.getChildren().add(template);
            }
    
            Scene scene = new Scene(root, 500, 450, Color.SILVER);
            primaryStage.setTitle("CustomStr");
            primaryStage.setScene(scene);
            primaryStage.show();
        }
  • 4. Re: How to realize alternative stroke types
    David Grieve Pro
    Currently Being Moderated
    javafx.scene.shape.SVGPath
  • 5. Re: How to realize alternative stroke types
    MiPa Pro
    Currently Being Moderated
    Thanks for the feedback so far but I probably was not very clear about what I want to achieve. Of course I know how to construct a new circle with a zigzag line for example. But what I am looking for is a possibility to apply different line styles to already existing shape objects in a similar way as you can do it in Java2D with a self-defined Stroke class. In order to implement something like this I would need to get a PathIterator or something similar for a Shape and have the ability to flatten this path. I am missing both features in JavaFX but perhaps I just overlooked something.
  • 6. Re: How to realize alternative stroke types
    fabsav Newbie
    Currently Being Moderated
    i think the only solution is to create a new shape...

    or try a "hack" like use images on borders :P (-fx-border-image). I never used it, but it should work :)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points