This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: documentation for Swing - Java data
- From: "Sudarshan S Chawathe" <chaw at eip10 dot org>
- To: Claude Marinier <claudem223 at gmail dot com>
- Cc: kawa at sourceware dot org
- Date: Fri, 16 Dec 2016 16:46:09 -0500
- Subject: Re: documentation for Swing - Java data
- Authentication-results: sourceware.org; auth=none
- Reply-to: "Sudarshan S Chawathe" <chaw at eip10 dot org>
> From: Claude Marinier <claudem223@gmail.com>
> Date: Fri, 16 Dec 2016 16:15:22 -0500
> I am experimenting with Kawa and Swing. I need to provide choices to
> a JComboBox and have not found documentation on how to pass data to
> Java/Swing.
>
> Where can I find this?
I'm not sure if I understand the question fully, but in general it is
easy to call Java constructors and methods from Kawa, and similarly to
pass Scheme data to Java via implicit or explicit conversion. The
chapter titled "Object, Classes and Modules" in the Kawa manual has many
useful details in this regard. (The "lambda as shorthand for an
anonymous class"/SAM-conversion is one of my favorite features,
especially when using Swing.)
A bit more specific to your question perhaps, the code fragment in the
JComboBox tutorial at
https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html
i.e.:
String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };
//Create the combo box, select item at index 4.
//Indices start at 0, so 4 specifies the pig.
JComboBox petList = new JComboBox(petStrings);
petList.setSelectedIndex(4);
petList.addActionListener(this);
may be written in Kawa along the following lines:
(let* ((pet-strings (String[] "Bird" "Cat" "Dog" "Rabbit" "Pig"))
(pet-list (javax.swing.JComboBox pet-strings)))
(pet-list:setSelectedIndex 4)
(pet-list:addActionListener (this)))
assuming it occurs in the the scope of a define-simple-class or
equivalent so that the (this) makes sense.
Regards,
-chaw