setting gradient background color on button

Skip to first unread message

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:

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

This doesn't work:

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

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

This neither:

(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

Nov 29, 2015, 11:12:10 PM11/29/15
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:

  (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
For more options, visit

Reply all
Reply to author
0 new messages