如何在 clojure seesaw 中使用滑块
How to use sliders in clojure seesaw
我是 clojure 的新手(甚至是跷跷板的新手),但有很多 Java 经验和相当多的摇摆经验。
我正在尝试创建一个 window,其中包含一些下拉文本框和一个滑块。但是,我无法将所有部分显示在一个 window 上(而不是一次显示一个),并且由于某种原因没有显示滑块。
我真的找不到很多这方面的教程,所以我可能遗漏了一些明显的东西。
这是我正在尝试做的...
(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)]
)
)
seesaw/input creates an input dialog, while you want to create a JComboBox. The wiki has a nice help about how to create widgets and you can find a list of available widgets in the API doc.
a frame you need 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))))
我是 clojure 的新手(甚至是跷跷板的新手),但有很多 Java 经验和相当多的摇摆经验。
我正在尝试创建一个 window,其中包含一些下拉文本框和一个滑块。但是,我无法将所有部分显示在一个 window 上(而不是一次显示一个),并且由于某种原因没有显示滑块。
我真的找不到很多这方面的教程,所以我可能遗漏了一些明显的东西。
这是我正在尝试做的...
(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)]
)
)
seesaw/input creates an input dialog, while you want to create a JComboBox. The wiki has a nice help about how to create widgets and you can find a list of available widgets in the API doc.
a frame you need 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))))