A Swing Button with 3D (Source Code+Demo)

During my JavaPolis talk entitled Extreme Swing I explained how to create a JButton with a 3D icon. I should have done this before, but I finally uploaded the the source code and a webstart demo. You will need Java 1.5 or 1.6.

JButton with 3D

JButton with 3D

The source code is very simple, just take a look at the file Button3dDemo.java.

P.S: I'll find some time this week to write a lengthy entry explaining how I created the Twinkle demo. I will also present the (really) small API I am using for my Swing/OpenGL demos.

7 Responses to “A Swing Button with 3D (Source Code+Demo)”

  1. skinny boy says:

    have you presented this small API you are refering to?
    i would appreciate it if i could get a link to it
    thanks in advance

  2. nantuko says:

    I’m also interested how to make this example working. May be you can provide steps to configure environment (with links to download necessary libs, etc.) so it would be easier to run your example just following the steps.
    At the moment I’ve installed jogl but “Could not initialize class com.sun.opengl.impl.windows.WindowsGLDrawableFactory” exception is thrown, seems jogl can’t be found at java.library.path but couldn’t manage that

  3. nantuko says:

    I’ve successed with the example in eclipse
    Here my steps:
    1. Download jogl for your OS
    different versions can be found here:
    As for me, I’ve downloaded this one:
    1b. Download and install java 3d:
    2. Unpack and copy libs (jars and native dlls) to any folder (g.e. c:\test\jogl\bin)
    3. Start Eclipse and create new java project (e.g. ButtonDemo)
    4. Eclipse
    4a.Open Eclipce Menu: Window->Preferencies
    Java-Build Path-User libraries
    4b. Press “New…”
    give some name, e.g. “JOGL”
    4c.Press “Add jars…”
    Add gluegen-rt.jar and jogl.jar from you folder (described above, c:\test\jogl\lib\)
    On the same window, point Native library location for jogl.jar, for me: c:/test/jogl/lib (it is where jogl.dll, jogl_awt.dll, gluegen-rt.dll, etc. are)
    5. Open ButtonDemo Project Properties,
    Java Build Path->Libraries->Add library…->Choose User Library->Check “JOGL” (from 4b.)
    6. You may need vecmath from Java\Java3D\ver\lib\ext
    So just copy it into project and add into Libraries (Java Build Path->Add JARS…)

    Now it works!

    p.s. send email to nantuko@mail.ru if you have any question

  4. petercc9 says:

    great instructions nantuko! I have the button running perfectly.

  5. Nick says:

    I don’t see any 3d model in my button. It just has “Preferences” in it.

    OSX 10.4.11
    java version “1.5.0_19”

  6. Nikita says:

    I don’t see anything but button with “Preferences” on macosx 10.6.4 java 1.6.0_20