Seesaw Image Example

445 views
Skip to first unread message

Tore

unread,
Nov 12, 2011, 8:10:21 PM11/12/11
to seesaw-clj
Hi,

First off, let me say that Seesaw is very awesome. I created 90% of my
gui in about 10 minutes (and I'm new to clojure!).

What I'm having trouble with, though, is adding an image to a label
(or button or whatever). I've gone through the wiki and the blog posts
and found examples of drawing, but not on how to load an image.

Do you know of any examples of using Seesaw to display an image from a
file in a label?

Thanks!

Tore

Dave Ray

unread,
Nov 12, 2011, 8:56:59 PM11/12/11
to seesa...@googlegroups.com
Hey,

Glad you're having fun so far.

A lot of things, including labels and buttons, have an :icon property
which you use to set their image. Of course it takes Swing icon
objects, but that's pretty inconventient so it also takes URLs or
strings that look like URLs. So you can do:

(label :text "FOO" :icon "http://example.com/path/to/foo.png")

but you don't really want to download that icon every time you run
your app, so you can put it on the classpath and access it with
clojure.java.io/resource:

(label :text "FOO" :icon (clojure.java.io/resource "my/project/foo.png"))

in a normal lein project, png would live in src/my/project/foo.png or
resources/my/project/foo.png.

Finally, you can also set the icon (and text, colors, fonts, etc) from
a resource bundle using i18n stuff as shown in this example:

https://github.com/daveray/seesaw/blob/develop/test/seesaw/test/examples/j18n.clj

Hope this helps,

Dave

Tore

unread,
Nov 12, 2011, 9:46:03 PM11/12/11
to seesaw-clj
Wow, thanks Dave!

That was incredibly easy! Thank you for the help!

On Nov 12, 5:56 pm, Dave Ray <dave...@gmail.com> wrote:
> Hey,
>
> Glad you're having fun so far.
>
> A lot of things, including labels and buttons, have an :icon property
> which you use to set their image. Of course it takes Swing icon
> objects, but that's pretty inconventient so it also takes URLs or
> strings that look like URLs. So you can do:
>
>      (label :text "FOO" :icon "http://example.com/path/to/foo.png")
>
> but you don't really want to download that icon every time you run
> your app, so you can put it on the classpath and access it with
> clojure.java.io/resource:
>
>     (label :text "FOO" :icon (clojure.java.io/resource "my/project/foo.png"))
>
> in a normal lein project, png would live in src/my/project/foo.png or
> resources/my/project/foo.png.
>
> Finally, you can also set the icon (and text, colors, fonts, etc) from
> a resource bundle using i18n stuff as shown in this example:
>
> https://github.com/daveray/seesaw/blob/develop/test/seesaw/test/examp...

Dave Ray

unread,
Nov 12, 2011, 9:54:49 PM11/12/11
to seesa...@googlegroups.com
No problem. :)
Reply all
Reply to author
Forward
0 new messages