Stack Panes and Z-Position

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Stack Panes and Z-Position

David McNelis

Morning,

 

In the tutorial documentation for the stack panes it says, “Components with a higher z-index (position within the stack pane) are painted on top of components with a lower z-index.”  Is there a simple way to get and set the z position of elements inside a stack pane outside of the order in which they are painted?

 

For example, if I were to loop through an array of items to draw (specifically Rectangles in this case) that may or may not be ordered in the array, and I want element 2 to end up on top of element 3…is there a way to do this outside of repainting element 2 after all the objects have been created?

 

Or in a different scenario to loop through the objects inside the pane and retrieve the z-index of each of the elements….though I suppose the sequence is an ordered list, so that is possible already at this point.

 

Thanks,

David

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Stack Panes and Z-Position

Greg Brown
Administrator
<base href="x-msg://59/">
Is there a simple way to get and set the z position of elements inside a stack pane outside of the order in which they are painted?

I'm not sure I understand the question. By definition, the z-index *is* the order in which components are painted.

For example, if I were to loop through an array of items to draw (specifically Rectangles in this case) that may or may not be ordered in the array, and I want element 2 to end up on top of element 3…is there a way to do this outside of repainting element 2 after all the objects have been created?

How are you planning to draw the rectangles? Are you talking about instances of org.apache.pivot.wtk.media.drawing.Rectangle, or something else?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Stack Panes and Z-Position

Todd Volkert
In reply to this post by David McNelis

In the tutorial documentation for the stack panes it says, “Components with a higher z-index (position within the stack pane) are painted on top of components with a lower z-index.”  Is there a simple way to get and set the z position of elements inside a stack pane outside of the order in which they are painted?


You can use Container.indexOf(Component) to find a child component's z-order, and you can use Container.move(int,int) to move a component within a StackPane.

Cheers,
-T
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Stack Panes and Z-Position

David McNelis
In reply to this post by Greg Brown
<base href="x-msg://59/">

I am referring to instances of org.apache.pivot.wtk.media.drawing.Rectangle.  I probably started down the wrong path trying to get the z-index of the object…I should just paint the objects in the order they should actually appear.

 

That brings me to another problem to solve, though.  It doesn’t look like I can make a Button transparent, and what I’m attempting to do is draw a set of shapes and trigger an action when the shape is clicked.

 

My first thought was to use a ComponentMouseButtonListener and then use the pane’s getComponentAt(x,y) argument, but that returns components, and while I see how to get the components parent, I don’t see how to get back down to the rectangle that the user actually clicked.  Would it make more sense for me to create filled borders instead of drawing rectangles?  That seems like it would work with rectangular objects, but not other shapes.

 

The Canvas, Rectangle, and ImageView listeners don’t look like they have any kind of mouse button listeners available.

 

 

 

From: Greg Brown [mailto:[hidden email]]
Sent: Wednesday, February 24, 2010 8:29 AM
To: [hidden email]
Subject: Re: Stack Panes and Z-Position

 

Is there a simple way to get and set the z position of elements inside a stack pane outside of the order in which they are painted?

 

I'm not sure I understand the question. By definition, the z-index *is* the order in which components are painted.

 

For example, if I were to loop through an array of items to draw (specifically Rectangles in this case) that may or may not be ordered in the array, and I want element 2 to end up on top of element 3…is there a way to do this outside of repainting element 2 after all the objects have been created?

 

How are you planning to draw the rectangles? Are you talking about instances of org.apache.pivot.wtk.media.drawing.Rectangle, or something else?

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Stack Panes and Z-Position

Greg Brown
Administrator
<base href="x-msg://59/">
That brings me to another problem to solve, though.  It doesn’t look like I can make a Button transparent, and what I’m attempting to do is draw a set of shapes and trigger an action when the shape is clicked.

You can do this in a couple of ways. You can set the button's color, background color, and border color to a color with an alpha value, but the easier way would be to use an instance of org.apache.pivot.wtk.effects.FadeDecorator.

My first thought was to use a ComponentMouseButtonListener and then use the pane’s getComponentAt(x,y) argument, but that returns components, and while I see how to get the components parent, I don’t see how to get back down to the rectangle that the user actually clicked.  Would it make more sense for me to create filled borders instead of drawing rectangles?  That seems like it would work with rectangular objects, but not other shapes.

The org.apache.pivot.wtk.media.drawing.Group class has a getShapeAt() method you can use for this.

 The Canvas, Rectangle, and ImageView listeners don’t look like they have any kind of mouse button listeners available.

Shapes don't have mouse button listeners but ImageView does (it extends Component).


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Stack Panes and Z-Position

David McNelis
<base href="x-msg://59/">

That is infinitely helpful, thanks!  getShapeAt() does just what I need.  The FadeDecorator information is pretty useful too.  Thanks, Greg!

 

From: Greg Brown [mailto:[hidden email]]
Sent: Wednesday, February 24, 2010 9:13 AM
To: [hidden email]
Subject: Re: Stack Panes and Z-Position

 

That brings me to another problem to solve, though.  It doesn’t look like I can make a Button transparent, and what I’m attempting to do is draw a set of shapes and trigger an action when the shape is clicked.

 

You can do this in a couple of ways. You can set the button's color, background color, and border color to a color with an alpha value, but the easier way would be to use an instance of org.apache.pivot.wtk.effects.FadeDecorator.


getComponentAt(x,y) argument, but that returns components, and while I see how to get the components parent, I don’t see how to get back down to the rectangle that the user actually clicked.  Would it make more sense for me to create filled borders instead of drawing rectangles?  That seems like it would work with rectangular objects, but not other shapes.

 

My first thought was to use a ComponentMouseButtonListener and then use the pane’s

The org.apache.pivot.wtk.media.drawing.Group class has a getShapeAt() method you can use for this.



 The Canvas, Rectangle, and ImageView listeners don’t look like they have any kind of mouse button listeners available.

 

Shapes don't have mouse button listeners but ImageView does (it extends Component).

 

 

Loading...