I have some problems with using swing from clojure. Starting from the
working choice list:

(defn direct-ui
  ""
  []
  (let [
        tmp-my-list (doto (new DefaultListModel)
                        (.addElement "Item1")
                        (.addElement "Item2")
                        (.addElement "Item3"))
        ChoiceList (new JList tmp-my-list)
        panel (miglayout (JPanel.)
                         ChoiceList)
        Frame (doto (new JFrame "Set choice")
                (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
                (.add panel)
                (.pack)
                (.setVisible true))]
    (println "done\n")))

I want to read the elements in the ChoiceList ("Item1"..."Item3") from
a vector. So I wrote a function:

(defn new-list-fn [l]
  (concat '(doto (new DefaultListModel)) (map #(list '.addElement %)
l)))

the function returns exactly the vector I want:

user> (new-list-fn ["Item1" "Item2" "Item3"])
(doto (new DefaultListModel) (.addElement "Item1") (.addElement
"Item2") (.addElement "Item3"))


but if I use it inside the let-construction as in:

(defn function-ui
  ""
  []
  (let [
        my-list ["Item1" "Item2" "Item3"]
        tmp-my-list (new-list-fn my-list)
        ChoiceList (new JList tmp-my-list)
        panel (miglayout (JPanel.)
                         ChoiceList)
        Frame (doto (new JFrame "Set choice")
                (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
                (.add panel)
                (.pack)
                (.setVisible true))]
    (println "done\n")))

I get the error:

No matching ctor found for class javax.swing.JList
  [Thrown class java.lang.IllegalArgumentException]


I tested also using a macro:

(defmacro new-list-macro [l]
  (concat '(doto (new DefaultListModel)) (map #(list '.addElement %)
l)))

it works when calling directly with the vector:

(defn macro-ui
  ""
  []
  (let [
        tmp-my-list (new-list-macro ["Item1" "Item2" "Item3"])
        ChoiceList (new JList tmp-my-list)
        panel (miglayout (JPanel.)
                         ChoiceList)
        Frame (doto (new JFrame "Set choice")
                (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
                (.add panel)
                (.pack)
                (.setVisible true))]
    (println "done\n")))

but not when calling:

(defn macro-ui
  ""
  []
  (let [
        my-list ["Item1" "Item2" "Item3"]
        ; tmp-my-list (new-list-macro ["Item1" "Item2" "Item3"])
        tmp-my-list (new-list-macro my-list)
        ChoiceList (new JList tmp-my-list)
        panel (miglayout (JPanel.)
                         ChoiceList)
        Frame (doto (new JFrame "Set choice")
                (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
                (.add panel)
                (.pack)
                (.setVisible true))]
    (println "done\n")))



then I get:

java.lang.IllegalArgumentException: Don't know how to create ISeq
from: Symbol
  [Thrown class java.lang.RuntimeException]



Can anyone help with a hint?

Regards
Volker



The whole code I used:

(ns rudi
  (:import (javax.swing DefaultListModel ListSelectionModel JMenu
JMenuBar JMenuItem JButton JFrame JLabel JList JPanel
                        JTextField JTextArea
                        SwingUtilities))
  (:import (javax.accessibility))
  (:import (java.io IOException PrintStream OutputStream))
  (:use (clojure.contrib
         [miglayout]
         [swing-utils])))


(defmacro new-list-macro [l]
  (concat '(doto (new DefaultListModel)) (map #(list '.addElement %)
l)))

(defn new-list-fn [l]
  (concat '(doto (new DefaultListModel)) (map #(list '.addElement %)
l)))


(defn direct-ui
  ""
  []
  (let [
        tmp-my-list (doto (new DefaultListModel)
                        (.addElement "Item1")
                        (.addElement "Item2")
                        (.addElement "Item3"))
        ChoiceList (new JList tmp-my-list)
        panel (miglayout (JPanel.)
                         ChoiceList)
        Frame (doto (new JFrame "Set choice")
                (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
                (.add panel)
                (.pack)
                (.setVisible true))]
    (println "done\n")))

(defn macro-ui
  ""
  []
  (let [
        my-list ["Item1" "Item2" "Item3"]
        tmp-my-list (new-list-macro ["Item1" "Item2" "Item3"])
        ;tmp-my-list (new-list-macro my-list)
        ChoiceList (new JList tmp-my-list)
        panel (miglayout (JPanel.)
                         ChoiceList)
        Frame (doto (new JFrame "Set choice")
                (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
                (.add panel)
                (.pack)
                (.setVisible true))]
    (println "done\n")))

(defn function-ui
  ""
  []
  (let [
        my-list ["Item1" "Item2" "Item3"]
        tmp-my-list (new-list-fn my-list)
        ChoiceList (new JList tmp-my-list)
        panel (miglayout (JPanel.)
                         ChoiceList)
        Frame (doto (new JFrame "Set choice")
                (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
                (.add panel)
                (.pack)
                (.setVisible true))]
    (println "done\n")))




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to