Custom componentes

20 views
Skip to first unread message

MartonKiss

unread,
Nov 2, 2010, 8:49:38 AM11/2/10
to JavaBuilders
I try to use a date picker (I tried swingx and jcalendar), but just
can't get them to work as the non-custom components. I added this
component to the Persons example, so I just copy the parts that are
mine.
First I create the component in the persons.app:

private JXDatePicker dp;

Then I register it later in the main:

SwingJavaBuilder.getConfig().addType(org.jdesktop.swingx.JXDatePicker.class);

And in the YAML, I try to get some action like:

- JXDatePicker(name=dp):
onMouseClicked: onMouseClickedTest

and nothing happens, though I can set the date property of dp and
onMouseClickedTest works just fine with any other non-custom
component. I have a strong feeling that I miss something important
here, but I just can't figure it out. Could anyone point me in the
right direction? Thanks.

Jacek Furmankiewicz

unread,
Nov 2, 2010, 8:52:54 AM11/2/10
to JavaBuilders
Have you seen the extensions project that Alexandre maintains:

http://kenai.com/projects/swingjavabuilderext/pages/Home

It already has bindings for SwingX. I've never worked with that
component library myself,
so Alexandre can probably give you better pointers.

MartonKiss

unread,
Nov 2, 2010, 9:33:47 AM11/2/10
to JavaBuilders
Yes, but I think that does basically the same thing that I do. Still
doesn't work for me. And I tried with other custom components, but
none of them worked. So I still think that I miss something here. Is
my approach OK in general?

Jacek Furmankiewicz

unread,
Nov 2, 2010, 9:38:44 AM11/2/10
to JavaBuilders
Out of curiosity have you tried it like this:

- JXDatePicker(name=dp, onMouseClicked=onMouseClickedTest)

should not make a difference, but just asking.

Also, what happens if you hook up a listener manually via Java code?
Does it work as expected?
Maybe JXDate has some other default event, line onSelected or
something?

I know folks have been using JXDatePicker with Swing JB, so it must be
possible.

Jacek

MartonKiss

unread,
Nov 2, 2010, 10:37:56 AM11/2/10
to JavaBuilders
I'm not sure what I should do here, but if "hooking up manually" means
dp.addActionListener..., then it's working. As far as your first
suggestion is concerned, you were right, that did not make a
difference.

Jacek Furmankiewicz

unread,
Nov 2, 2010, 11:39:04 AM11/2/10
to JavaBuilders
I can try to have a look at it, but will be a few days...pretty
swamped with 'regular' work right now :-(

Kiss Márton

unread,
Nov 2, 2010, 5:21:00 PM11/2/10
to javabu...@googlegroups.com
I'd appreciate it, I'm really stuck here. Until then I'll play around with the other features. Thank you very much.


Alexandre Navarro

unread,
Nov 2, 2010, 5:34:35 PM11/2/10
to javabu...@googlegroups.com, javabu...@googlegroups.com
What you do might work.
The problem is just that the listener does not work?
The datePicker is it correctly created by swingBuilder or not?

Alexandre

Envoyé de mon iPhone

Le 2 nov. 2010 à 22:21, Kiss Márton <kiss...@gmail.com> a écrit :

I'd appreciate it, I'm really stuck here. Until then I'll play around with the other features. Thank you very much.


--
You received this message because you are subscribed to the Google Groups "JavaBuilders" group.
To post to this group, send email to javabu...@googlegroups.com.
To unsubscribe from this group, send email to javabuilders...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javabuilders?hl=en.

Kiss Márton

unread,
Nov 2, 2010, 8:09:36 PM11/2/10
to javabu...@googlegroups.com
Well, it's getting to be really confusing. The databinding looks like working, but I think it's not. I don't know if it's okay to copy long code here, so for now I just copy the binding part of the yaml:

bind:
    - fName.text: this.person.firstName
    - dp.date: this.person.bornDate

and the snippet where I change the date from the PersonApp:

private void change() {
        i++;
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, i);
        date = cal.getTime();
        person.setBornDate(date);
        person.setFirstName(date.toString());
    }

A button does the changing. When I press it, the textfield changes nicely, but the datepicker does not, though when I run the code, the datepicker gets the initial value of the person.date property, and I don't get any warnings about the binding. So... I don't know if the datepicker is created correctly or not. And for the sake of complexity if I change the date on the datepicker manually, it does change the person.date property.

Jacek Furmankiewicz

unread,
Nov 3, 2010, 10:50:45 AM11/3/10
to JavaBuilders
The object is obviously created, because you see it on the screen :-)

For the databinding to work correctly, your person entity has to have
PropertyChangeSupport (the bane of two-way binding support in Java).
Does it have it?

For the listener, after Swing JB runs what is the count of the mouse
click listeners on the JXDatePicker? Is it 0 or 1?

Jacek Furmankiewicz

unread,
Nov 3, 2010, 10:52:36 AM11/3/10
to JavaBuilders
Plus, you're never stuck.

Worst case scenario you can get a private instance of the object in
your Java code

private JXDatePicker dp;

Swing JB will set the reference during the build process so it's not
null.

Once you got a reference to it on the Java side you can do whatever
you need to do manually via Java code, if required.

Kiss Márton

unread,
Nov 3, 2010, 7:17:29 PM11/3/10
to javabu...@googlegroups.com
You're right, of course, the databinding works, I just mistyped something at the firePropertyChange.

But I don't know how to check the count of mouse click listeners :/
Honestly, I've used NetBeans' GUI builder so far, so I'm not that familiar with listeners. But want to be :)

Kiss Márton

unread,
Dec 2, 2010, 11:20:41 AM12/2/10
to javabu...@googlegroups.com
I still can't get it work the way it's supposed to. If you have the
chance to take a closer look on jxdatepicker, it would be nice to see
a code snippet here that actually works, I mean that it's updating the
underlying app and stuff. Regarding to my previous entry, it turns out
that the databinding is not working either. Though I can get it work
manually, but it feels a bit like some kind of workaround, taking away
the coolness of javabuilders.

Jacek Furmankiewicz

unread,
Dec 3, 2010, 4:30:12 PM12/3/10
to JavaBuilders
Sorry, I don't know the JXSwing package at all... :-(

Will try to have a look at it in the next few weeks, time permitting...

Kiss Márton

unread,
Dec 3, 2010, 4:38:58 PM12/3/10
to javabu...@googlegroups.com
Great. Actually, it's no big deal if it's not the jxswing package, any
datepicker is ok for me :) I tried JCalendar
(http://www.toedter.com/en/jcalendar/index.html) beside JXDatePicker,
with the same result. Anyway, thanks, now I'm really curious what I'm
missing here.

On Fri, Dec 3, 2010 at 10:30 PM, Jacek Furmankiewicz <jac...@gmail.com> wrote:
> Sorry, I don't know the JXSwing package at all... :-(
>
> Will try to have a look at it in the next few weeks, time permitting...
>

Reply all
Reply to author
Forward
0 new messages