如何在clojure跷跷板中使用滑块

时间:2016-02-18 23:44:51

标签: clojure seesaw

我是clojure的新手(甚至更新的跷跷板),但拥有大量的Java经验和相当多的摇摆经验。

我尝试创建一个带有下拉文本框和滑块的窗口。但是,我无法将所有部分显示在一个窗口上(而不是一次显示一个窗口),并且出于某种原因,滑块未显示。

我真的找不到很多这方面的教程,所以也许我错过了一些明显的东西。

这是我想要做的......

    (defn window [cuisine-input rating-input location-slider]
        (seesaw/frame
        :title "Resturant Selector"
        :content (cuisine-input rating-input location-slider)
        :width 200
        :height 50
        :on-close :exit))


    (defn -main
    [& args]

        (def cuisine (seesaw/input "Please choose a type of cuisine: "
                           :choices ["Indian" "Japanese" "Chinese"
                                     "Burgers"]))

        (def rating (seesaw/input "Please choose the ideal rating: "
                        :choices ["1 star" "2 stars" "3 stars" "4 stars" 
                                  "5 stars"]))
        (def location (seesaw/slider 
                             :value 5 :min 0 :max 20 
                             :minor-tick-spacing 1 :major-tick-spacing 2 
                             :snap-to-ticks? true 
                             :paint-ticks? true :paint-labels? true))

        (def main-window (window cuisine rating location))
        (seesaw/pack! (window main-window))
        (seesaw/show! (window main-window))

我也尝试过这样的事情:

    (seesaw/frame :title "Resturant Selector" :on-close :exit
            :content (:items [ 
                     (seesaw/input "Please choose a type of cuisine: "
                           :choices ["Indian" "Japanese" "Chinese"
                                    "Burgers"])

                     (seesaw/input "Please choose the ideal rating: "
                        :choices ["1 star" "2 stars" "3 stars" "4 stars" 
                                  "5 stars"])

                     (seesaw/slider
                       :value 5 :min 0 :max 20
                       :minor-tick-spacing 1 :major-tick-spacing 2
                       :snap-to-ticks? true
                       :paint-ticks? true :paint-labels? true)]
                              )
            )

1 个答案:

答案 0 :(得分:1)

seesaw/input会创建input dialog,而您想要创建JComboBoxwiki对如何创建小部件提供了很好的帮助,您可以在API doc中找到可用小部件的列表。

要在a frame中拥有多个小部件,您需要a container

因此,对于您的特定示例,您将需要类似于:

的内容
(defn window [content]
  (seesaw/frame
    :title "Resturant Selector"
    :content content
    :width 200
    :height 50
    :on-close :close))

(defn -main
  [& args]
  (let [rating-label (seesaw/label :text "Please choose rating:")
        rating (seesaw/combobox :model ["1 star" "2 star"])
        location (seesaw/slider
                   :value 5 :min 0 :max 20
                   :minor-tick-spacing 1 :major-tick-spacing 2
                   :snap-to-ticks? true
                   :paint-ticks? true :paint-labels? true)

        main-window (window (seesaw/vertical-panel :items [rating-label rating location]))]
    (seesaw/invoke-later
      (seesaw/pack! main-window)
      (seesaw/show! main-window))))