Gradient Paint on PCanvas

15 views
Skip to first unread message

patrick...@yahoo.com

unread,
Jul 31, 2014, 4:02:51 PM7/31/14
to piccolo...@googlegroups.com
Hi,
     I have been attempting (unsuccessfully so far) to create a PCanvas with a GradienPaint background and then place my components onto the canvas.
     Could any one please tell me how to do this? setBackground() only accepts a Color and I can't find a way to pass a Paint (GradientPaint) object into
     the canvas creation/settings.

     Thanks for any help.

     Patrick.

Michael Heuer

unread,
Jul 31, 2014, 5:32:26 PM7/31/14
to piccolo...@googlegroups.com
Hello Patrick,

PCanvas is a Swing JComponent, so any method for painting a gradient
on the background of a JComponent should work, e.g.

http://stackoverflow.com/questions/14364291/jpanel-gradient-background

michael
> --
> You received this message because you are subscribed to the Google Groups
> "Piccolo2D Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to piccolo2d-use...@googlegroups.com.
> To post to this group, send email to piccolo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/piccolo2d-users.
> For more options, visit https://groups.google.com/d/optout.

patrick...@yahoo.com

unread,
Jul 31, 2014, 6:46:57 PM7/31/14
to piccolo...@googlegroups.com
Hi Michael,
                Thanks for the quick reply.
I did in fact try the exact method you recommended in the link; however overriding the paintComponent method fo the PCanvas as shown in the link does not produce
a Gradient paint background. It seems as though the super.paintComponent()  call still makes the background solid. Do you have any experience with this or
have you ever had to implement a gradient paint canvas background?

Thanks.

Patrick.

Michael Heuer

unread,
Jul 31, 2014, 6:50:41 PM7/31/14
to piccolo...@googlegroups.com
Hmm, you may also have to call setOpaque(false) or Swing might be
painting over the gradient with the background color.

Or if you're already doing that, then I'm not sure and will have to
look into it further.

michael

patrick...@yahoo.com

unread,
Jul 31, 2014, 8:29:14 PM7/31/14
to piccolo...@googlegroups.com
Hi Michael,
                setOpaque(false); does make the gradient visible; however, when this is applied to the canvas it also wipes out any PNode elements I have added to the PCanvas PLayer;  i.e. makes them no longer visible, but they appear to still be part of the PCanvas PLayer object.
Do I have to use different PLayers in the PCanvas for background and element components?  if so could you give me a quick explanation, or point me in the right direction as to how to do this please?

Many thanks for your help.


Patrick.


On Thursday, 31 July 2014 16:02:51 UTC-4, patrick...@yahoo.com wrote:
Reply all
Reply to author
Forward
0 new messages