setting gradient background color on button

52 views
Skip to first unread message

jun...@selma.hfmdk-frankfurt.de

unread,
Nov 29, 2015, 1:25:07 PM11/29/15
to seesaw-clj
I'm trying to change the background color for a button. Since the default theme uses gradients I'd like to paint it with gradients, too. Unfortuately the following gives an error:

This works:

(do
 
(def my-button (button))
   
(config! my-button :background :red))





This doesn't work:

(do
 
(def my-button (button))
   
(config! my-button :background (linear-gradient :start [0 0] :end [0 1] :colors [:red :white])))


=> 1. Unhandled java.lang.ClassCastException
   java
.awt.LinearGradientPaint cannot be cast to clojure.lang.Named




This neither:

(do
 
(def my-button (button))
 
(config! my-button :style (style :background (linear-gradient :start [0 0] :end [0 1] :colors [:red :white]))))


=> 1. Unhandled java.lang.IllegalArgumentException
       
class seesaw.core.proxy$javax.swing.JButton$Tag$fd407141 does not
        support the
:style option


How is this done?

Dave Ray

unread,
Nov 29, 2015, 11:12:10 PM11/29/15
to seesa...@googlegroups.com
The :background property just passes through to setBackground [1] which only supports Color objects as arguments.

The only approach I know of is to override painting of the button. See the docstring for seesaw.core/canvas. For a button it would be something like:

(do
  (def my-button (button))
  (config! my-button :paint (fn [^java.awt.Graphics2D g] ... paint gradient ...)))

There's a java example of drawing a gradient here [2].

--
You received this message because you are subscribed to the Google Groups "seesaw-clj" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seesaw-clj+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages