Rectangle with rounded corner as ProgressBar using Path












3















i need to draw rectangle rounded corner with progressbar in javafx.

i already did some code which draw rectangle with corner.
but how do i show progress effect.
Following are the example which I am trying to imitate.
http://jsfiddle.net/m1erickson/P2qTq/



there is any other way to do this. guide me thank you.



void drawLine(double x1,double  y1,double x2,double y2) {
MoveTo move= new MoveTo(x1, y1);
path.getElements().add(move);
LineTo line= new LineTo(x2,y2);
path.getElements().add(line);
path.setStroke(Paint.valueOf("#000000"));
}

void drawCorner(double x0,double y0,double x1,double y1) {
QuadCurveTo quadCurveTo=new QuadCurveTo();
quadCurveTo.setX(x0);
quadCurveTo.setY(y0);
quadCurveTo.setControlX(x1);
quadCurveTo.setControlY(y1);
path.getElements().add(quadCurveTo);
}

Group group=new Group();
double angleTRX=offsetX+horizontalLength+cornerRadius;
double angleTRY=offsetY+cornerRadius;
double TRCornerX=offsetX+horizontalLength+cornerRadius;
double TRCornerY=offsetY;
double bottomRY=angleTRY+verticalLength;

//draw top line
drawLine(offsetX, offsetY, offsetX + horizontalLength, offsetY);
//draw top right corner
drawCorner(angleTRX, offsetY+cornerRadius, TRCornerX, offsetY);
//draw right line
drawLine(angleTRX,angleTRY, angleTRX,bottomRY);
//draw bottom right corner
drawCorner(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX+horizontalLength+cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw bottom line
drawLine(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX,offsetY+verticalLength+cornerRadius*2);
//draw left bottom corner
drawCorner(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw left line
drawLine(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+cornerRadius);
//draw top left corner
drawCorner(offsetX,offsetY,offsetX-cornerRadius,offsetY);
group.getChildren().add(path);


--> Update <--



i found another way to do it. using Rectangle with stroke-offset.
but still facing one issue stroke are starting from clockwise.



Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setArcHeight(cornerRadius);
rectangle.setArcWidth(cornerRadius);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Paint.valueOf("#ffffff"));
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;
//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);
//display empty stroke/border
rectangle.setStrokeDashOffset(length);
group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
rectangle.setStrokeDashOffset(length-(length*(newValue.doubleValue()/100)));
});


if you know better solution then please let me know.










share|improve this question

























  • (Correct me If I am wrong but.. ) If all you want is to make the ProgressBar to have rounded corners,you can achieve it by applying some CSS on it you don't actually have to reinvent the wheel.

    – JKostikiadis
    Nov 20 '18 at 13:53













  • no i don't want to do this. actually i want to do draw progressbar in square format look into following jsfiddle link found on google. jsfiddle.net/m1erickson/P2qTq

    – mcd
    Nov 20 '18 at 14:01






  • 3





    Oh I get it now. If it is possible edit your question and add the link you provide in the commend above to help others as well.

    – JKostikiadis
    Nov 20 '18 at 14:25
















3















i need to draw rectangle rounded corner with progressbar in javafx.

i already did some code which draw rectangle with corner.
but how do i show progress effect.
Following are the example which I am trying to imitate.
http://jsfiddle.net/m1erickson/P2qTq/



there is any other way to do this. guide me thank you.



void drawLine(double x1,double  y1,double x2,double y2) {
MoveTo move= new MoveTo(x1, y1);
path.getElements().add(move);
LineTo line= new LineTo(x2,y2);
path.getElements().add(line);
path.setStroke(Paint.valueOf("#000000"));
}

void drawCorner(double x0,double y0,double x1,double y1) {
QuadCurveTo quadCurveTo=new QuadCurveTo();
quadCurveTo.setX(x0);
quadCurveTo.setY(y0);
quadCurveTo.setControlX(x1);
quadCurveTo.setControlY(y1);
path.getElements().add(quadCurveTo);
}

Group group=new Group();
double angleTRX=offsetX+horizontalLength+cornerRadius;
double angleTRY=offsetY+cornerRadius;
double TRCornerX=offsetX+horizontalLength+cornerRadius;
double TRCornerY=offsetY;
double bottomRY=angleTRY+verticalLength;

//draw top line
drawLine(offsetX, offsetY, offsetX + horizontalLength, offsetY);
//draw top right corner
drawCorner(angleTRX, offsetY+cornerRadius, TRCornerX, offsetY);
//draw right line
drawLine(angleTRX,angleTRY, angleTRX,bottomRY);
//draw bottom right corner
drawCorner(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX+horizontalLength+cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw bottom line
drawLine(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX,offsetY+verticalLength+cornerRadius*2);
//draw left bottom corner
drawCorner(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw left line
drawLine(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+cornerRadius);
//draw top left corner
drawCorner(offsetX,offsetY,offsetX-cornerRadius,offsetY);
group.getChildren().add(path);


--> Update <--



i found another way to do it. using Rectangle with stroke-offset.
but still facing one issue stroke are starting from clockwise.



Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setArcHeight(cornerRadius);
rectangle.setArcWidth(cornerRadius);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Paint.valueOf("#ffffff"));
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;
//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);
//display empty stroke/border
rectangle.setStrokeDashOffset(length);
group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
rectangle.setStrokeDashOffset(length-(length*(newValue.doubleValue()/100)));
});


if you know better solution then please let me know.










share|improve this question

























  • (Correct me If I am wrong but.. ) If all you want is to make the ProgressBar to have rounded corners,you can achieve it by applying some CSS on it you don't actually have to reinvent the wheel.

    – JKostikiadis
    Nov 20 '18 at 13:53













  • no i don't want to do this. actually i want to do draw progressbar in square format look into following jsfiddle link found on google. jsfiddle.net/m1erickson/P2qTq

    – mcd
    Nov 20 '18 at 14:01






  • 3





    Oh I get it now. If it is possible edit your question and add the link you provide in the commend above to help others as well.

    – JKostikiadis
    Nov 20 '18 at 14:25














3












3








3


0






i need to draw rectangle rounded corner with progressbar in javafx.

i already did some code which draw rectangle with corner.
but how do i show progress effect.
Following are the example which I am trying to imitate.
http://jsfiddle.net/m1erickson/P2qTq/



there is any other way to do this. guide me thank you.



void drawLine(double x1,double  y1,double x2,double y2) {
MoveTo move= new MoveTo(x1, y1);
path.getElements().add(move);
LineTo line= new LineTo(x2,y2);
path.getElements().add(line);
path.setStroke(Paint.valueOf("#000000"));
}

void drawCorner(double x0,double y0,double x1,double y1) {
QuadCurveTo quadCurveTo=new QuadCurveTo();
quadCurveTo.setX(x0);
quadCurveTo.setY(y0);
quadCurveTo.setControlX(x1);
quadCurveTo.setControlY(y1);
path.getElements().add(quadCurveTo);
}

Group group=new Group();
double angleTRX=offsetX+horizontalLength+cornerRadius;
double angleTRY=offsetY+cornerRadius;
double TRCornerX=offsetX+horizontalLength+cornerRadius;
double TRCornerY=offsetY;
double bottomRY=angleTRY+verticalLength;

//draw top line
drawLine(offsetX, offsetY, offsetX + horizontalLength, offsetY);
//draw top right corner
drawCorner(angleTRX, offsetY+cornerRadius, TRCornerX, offsetY);
//draw right line
drawLine(angleTRX,angleTRY, angleTRX,bottomRY);
//draw bottom right corner
drawCorner(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX+horizontalLength+cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw bottom line
drawLine(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX,offsetY+verticalLength+cornerRadius*2);
//draw left bottom corner
drawCorner(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw left line
drawLine(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+cornerRadius);
//draw top left corner
drawCorner(offsetX,offsetY,offsetX-cornerRadius,offsetY);
group.getChildren().add(path);


--> Update <--



i found another way to do it. using Rectangle with stroke-offset.
but still facing one issue stroke are starting from clockwise.



Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setArcHeight(cornerRadius);
rectangle.setArcWidth(cornerRadius);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Paint.valueOf("#ffffff"));
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;
//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);
//display empty stroke/border
rectangle.setStrokeDashOffset(length);
group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
rectangle.setStrokeDashOffset(length-(length*(newValue.doubleValue()/100)));
});


if you know better solution then please let me know.










share|improve this question
















i need to draw rectangle rounded corner with progressbar in javafx.

i already did some code which draw rectangle with corner.
but how do i show progress effect.
Following are the example which I am trying to imitate.
http://jsfiddle.net/m1erickson/P2qTq/



there is any other way to do this. guide me thank you.



void drawLine(double x1,double  y1,double x2,double y2) {
MoveTo move= new MoveTo(x1, y1);
path.getElements().add(move);
LineTo line= new LineTo(x2,y2);
path.getElements().add(line);
path.setStroke(Paint.valueOf("#000000"));
}

void drawCorner(double x0,double y0,double x1,double y1) {
QuadCurveTo quadCurveTo=new QuadCurveTo();
quadCurveTo.setX(x0);
quadCurveTo.setY(y0);
quadCurveTo.setControlX(x1);
quadCurveTo.setControlY(y1);
path.getElements().add(quadCurveTo);
}

Group group=new Group();
double angleTRX=offsetX+horizontalLength+cornerRadius;
double angleTRY=offsetY+cornerRadius;
double TRCornerX=offsetX+horizontalLength+cornerRadius;
double TRCornerY=offsetY;
double bottomRY=angleTRY+verticalLength;

//draw top line
drawLine(offsetX, offsetY, offsetX + horizontalLength, offsetY);
//draw top right corner
drawCorner(angleTRX, offsetY+cornerRadius, TRCornerX, offsetY);
//draw right line
drawLine(angleTRX,angleTRY, angleTRX,bottomRY);
//draw bottom right corner
drawCorner(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX+horizontalLength+cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw bottom line
drawLine(offsetX+horizontalLength,offsetY+verticalLength+cornerRadius*2,
offsetX,offsetY+verticalLength+cornerRadius*2);
//draw left bottom corner
drawCorner(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+verticalLength+cornerRadius*2);
//draw left line
drawLine(offsetX-cornerRadius,offsetY+verticalLength+cornerRadius,
offsetX-cornerRadius,offsetY+cornerRadius);
//draw top left corner
drawCorner(offsetX,offsetY,offsetX-cornerRadius,offsetY);
group.getChildren().add(path);


--> Update <--



i found another way to do it. using Rectangle with stroke-offset.
but still facing one issue stroke are starting from clockwise.



Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setArcHeight(cornerRadius);
rectangle.setArcWidth(cornerRadius);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Paint.valueOf("#ffffff"));
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;
//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);
//display empty stroke/border
rectangle.setStrokeDashOffset(length);
group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
rectangle.setStrokeDashOffset(length-(length*(newValue.doubleValue()/100)));
});


if you know better solution then please let me know.







javafx graphics javafx-8 graphics2d javafx-9






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 10:09







mcd

















asked Nov 20 '18 at 13:08









mcdmcd

1,2751226




1,2751226













  • (Correct me If I am wrong but.. ) If all you want is to make the ProgressBar to have rounded corners,you can achieve it by applying some CSS on it you don't actually have to reinvent the wheel.

    – JKostikiadis
    Nov 20 '18 at 13:53













  • no i don't want to do this. actually i want to do draw progressbar in square format look into following jsfiddle link found on google. jsfiddle.net/m1erickson/P2qTq

    – mcd
    Nov 20 '18 at 14:01






  • 3





    Oh I get it now. If it is possible edit your question and add the link you provide in the commend above to help others as well.

    – JKostikiadis
    Nov 20 '18 at 14:25



















  • (Correct me If I am wrong but.. ) If all you want is to make the ProgressBar to have rounded corners,you can achieve it by applying some CSS on it you don't actually have to reinvent the wheel.

    – JKostikiadis
    Nov 20 '18 at 13:53













  • no i don't want to do this. actually i want to do draw progressbar in square format look into following jsfiddle link found on google. jsfiddle.net/m1erickson/P2qTq

    – mcd
    Nov 20 '18 at 14:01






  • 3





    Oh I get it now. If it is possible edit your question and add the link you provide in the commend above to help others as well.

    – JKostikiadis
    Nov 20 '18 at 14:25

















(Correct me If I am wrong but.. ) If all you want is to make the ProgressBar to have rounded corners,you can achieve it by applying some CSS on it you don't actually have to reinvent the wheel.

– JKostikiadis
Nov 20 '18 at 13:53







(Correct me If I am wrong but.. ) If all you want is to make the ProgressBar to have rounded corners,you can achieve it by applying some CSS on it you don't actually have to reinvent the wheel.

– JKostikiadis
Nov 20 '18 at 13:53















no i don't want to do this. actually i want to do draw progressbar in square format look into following jsfiddle link found on google. jsfiddle.net/m1erickson/P2qTq

– mcd
Nov 20 '18 at 14:01





no i don't want to do this. actually i want to do draw progressbar in square format look into following jsfiddle link found on google. jsfiddle.net/m1erickson/P2qTq

– mcd
Nov 20 '18 at 14:01




3




3





Oh I get it now. If it is possible edit your question and add the link you provide in the commend above to help others as well.

– JKostikiadis
Nov 20 '18 at 14:25





Oh I get it now. If it is possible edit your question and add the link you provide in the commend above to help others as well.

– JKostikiadis
Nov 20 '18 at 14:25












1 Answer
1






active

oldest

votes


















3














i solved it using Rectangle and stroke-dash-offset. this might help others and save its valuable time.



    Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Color.TRANSPARENT);
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
// rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;

//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);

//display empty stroke/border
rectangle.setStrokeDashOffset(length);

group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
double offset=length-((length*(newValue.doubleValue()/100)));
rectangle.setStrokeDashOffset(-offset);
});





share|improve this answer



















  • 1





    That was exactly what i had in mind as well, also in case you want to round the corners of the rectangle you could use the rectangle.setArcHeight(radius); and rectangle.setArcWidth(radius);. Lastly I would use setStrokeLineCap(StrokeLineCap.BUTT) to make the 'loading" took the same as the link you provided.

    – JKostikiadis
    Nov 21 '18 at 17:24













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393712%2frectangle-with-rounded-corner-as-progressbar-using-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














i solved it using Rectangle and stroke-dash-offset. this might help others and save its valuable time.



    Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Color.TRANSPARENT);
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
// rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;

//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);

//display empty stroke/border
rectangle.setStrokeDashOffset(length);

group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
double offset=length-((length*(newValue.doubleValue()/100)));
rectangle.setStrokeDashOffset(-offset);
});





share|improve this answer



















  • 1





    That was exactly what i had in mind as well, also in case you want to round the corners of the rectangle you could use the rectangle.setArcHeight(radius); and rectangle.setArcWidth(radius);. Lastly I would use setStrokeLineCap(StrokeLineCap.BUTT) to make the 'loading" took the same as the link you provided.

    – JKostikiadis
    Nov 21 '18 at 17:24


















3














i solved it using Rectangle and stroke-dash-offset. this might help others and save its valuable time.



    Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Color.TRANSPARENT);
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
// rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;

//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);

//display empty stroke/border
rectangle.setStrokeDashOffset(length);

group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
double offset=length-((length*(newValue.doubleValue()/100)));
rectangle.setStrokeDashOffset(-offset);
});





share|improve this answer



















  • 1





    That was exactly what i had in mind as well, also in case you want to round the corners of the rectangle you could use the rectangle.setArcHeight(radius); and rectangle.setArcWidth(radius);. Lastly I would use setStrokeLineCap(StrokeLineCap.BUTT) to make the 'loading" took the same as the link you provided.

    – JKostikiadis
    Nov 21 '18 at 17:24
















3












3








3







i solved it using Rectangle and stroke-dash-offset. this might help others and save its valuable time.



    Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Color.TRANSPARENT);
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
// rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;

//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);

//display empty stroke/border
rectangle.setStrokeDashOffset(length);

group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
double offset=length-((length*(newValue.doubleValue()/100)));
rectangle.setStrokeDashOffset(-offset);
});





share|improve this answer













i solved it using Rectangle and stroke-dash-offset. this might help others and save its valuable time.



    Rectangle rectangle= new Rectangle();
rectangle.setX(offsetX);
rectangle.setY(offsetY);
rectangle.setWidth(200);
rectangle.setHeight(200);
rectangle.setStroke(Paint.valueOf("#000000"));
rectangle.setFill(Color.TRANSPARENT);
rectangle.setStrokeWidth(5);
rectangle.setStrokeMiterLimit(5);
rectangle.setSmooth(true);
rectangle.setStrokeLineCap(StrokeLineCap.ROUND);
// rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND);
double length=rectangle.getWidth()*2+rectangle.getHeight()*2;

//set stroke dash length
rectangle.getStrokeDashArray().addAll(length);

//display empty stroke/border
rectangle.setStrokeDashOffset(length);

group.getChildren().add(rectangle);
container.add(group,0,0);

slider.valueProperty().addListener((observable, oldValue, newValue) -> {
double offset=length-((length*(newValue.doubleValue()/100)));
rectangle.setStrokeDashOffset(-offset);
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 11:43









mcdmcd

1,2751226




1,2751226








  • 1





    That was exactly what i had in mind as well, also in case you want to round the corners of the rectangle you could use the rectangle.setArcHeight(radius); and rectangle.setArcWidth(radius);. Lastly I would use setStrokeLineCap(StrokeLineCap.BUTT) to make the 'loading" took the same as the link you provided.

    – JKostikiadis
    Nov 21 '18 at 17:24
















  • 1





    That was exactly what i had in mind as well, also in case you want to round the corners of the rectangle you could use the rectangle.setArcHeight(radius); and rectangle.setArcWidth(radius);. Lastly I would use setStrokeLineCap(StrokeLineCap.BUTT) to make the 'loading" took the same as the link you provided.

    – JKostikiadis
    Nov 21 '18 at 17:24










1




1





That was exactly what i had in mind as well, also in case you want to round the corners of the rectangle you could use the rectangle.setArcHeight(radius); and rectangle.setArcWidth(radius);. Lastly I would use setStrokeLineCap(StrokeLineCap.BUTT) to make the 'loading" took the same as the link you provided.

– JKostikiadis
Nov 21 '18 at 17:24







That was exactly what i had in mind as well, also in case you want to round the corners of the rectangle you could use the rectangle.setArcHeight(radius); and rectangle.setArcWidth(radius);. Lastly I would use setStrokeLineCap(StrokeLineCap.BUTT) to make the 'loading" took the same as the link you provided.

– JKostikiadis
Nov 21 '18 at 17:24






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393712%2frectangle-with-rounded-corner-as-progressbar-using-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents