participate


JavaFX Script Basics - Setting stroke on Rectangle: StackOverflowError
This question is answered. Correct Answer available

<<   Back to Forum  |   Give us Feedback Topics: « Previous | Next
1 Duke Stars rewarded for this thread
This topic has 2 replies on 1 page.
ratlan
Posts:4
Registered: 1/10/09
Setting stroke on Rectangle: StackOverflowError   
Jan 12, 2009 12:26 PM
 
 
Hi,
what's wrong with this code? It aborts with StackOverflowError.
Comment-out the marked line to run without error.

Greetings, ratlan

package experimentscene;
 
import javafx.ext.swing.SwingButton;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
 
var g1:Group;
var scene1 : Scene = Scene
    {
    content: [
        g1 = Group {
            content: [
                Rectangle {
                    fill:Color.BLUE
                    arcHeight:10;
                    arcWidth:10;
                    strokeWidth:2;
                    stroke: Color.RED;   // <-- comment-out this line to avoid error
                    width: bind g1.layoutBounds.width
                    height: bind g1.layoutBounds.height
                },
                SwingButton {
                    translateX:10;
                    text:"btn";
                }
            ]}
    ]
}
 
Stage {
    width: 250
    height: 80
    scene:bind scene1
}
 
stemkev
Posts:34
Registered: 4/13/07
Re: Setting stroke on Rectangle: StackOverflowError   
Jan 12, 2009 3:31 PM (reply 1 of 2)  (In reply to original post )
Correct
 
Hi Ratlan,
I think the stack overflow is caused by binding the width of the rectangle to the width of the group. But the width of the group is determined by the width of its children, which includes the rectangle. I don't know why it works when you comment out the Stroke line. Try setting the width to hard-coded values and putting the Stroke back in just to see what happens.

If you're trying to achieve the effect where the rectangle is the same size as the stage/scene, then you should bind the rectangle width to scene.width.

HTH,
Kevin
 
PhiLho
Posts:1,533
Registered: 17/05/06
Re: Setting stroke on Rectangle: StackOverflowError      
Jan 16, 2009 1:37 PM (reply 2 of 2)  (In reply to #1 )
Helpful
 
Good catch stemkev.
I think I know why the stroke color changes the behavior: without it, the rectangle is exactly of the size of the Group, so no positive feed-back inducing the (almost) infinite loop. By specifying a color, the shape is widened by 1 pixel, 3 if strokeWidth is 2, etc. -- width seems to be around the shape frontier!
 
This topic has 2 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 129

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums