# A Titled JavaFX Separator

In the process of updating some old programs, I had to change the GUI frameworks used. The old programs were written in Java using the Swing GUI framework and the JGoodies Forms and Looks libraries. Nowadays, the official GUI framework for Java is JavaFX.

Making the transition from Swing to JavaFX was relatively painless because the programs were so small. However, one of the things I missed from the JGoodies Forms library was the “titled separator”, that is a separator with a label in front of it. I really liked the look. Turns out that making my own wasn’t that difficult. Here’s a program extract that implements my version. (This time it’s written in Clojure.)

(def sep-color "#4682b4")                                   ; steelblue
(def sep-style (str/join "" ["-fx-border-color: "
sep-color
"; -fx-border-width: 1 0 0 0 ;"]))

(defn special-separator
"Return a special separator used for titled separators below. This
separator is specially colored and set to fill as much space as
available in the HBox where it is used."
[]
(let [sep (Separator.)]
(doto sep
(.setStyle sep-style)
(HBox/setHgrow Priority/ALWAYS))
sep))

(defn titled-separator
"Return a separator with a title preceding the separator line. If title
is empty or nil, a separator consisting of only the line is returned."
[title]
(let [labeled-separator (HBox.)
no-label (or (nil? title)
(zero? (count title)))
label (if no-label
(Label. "")
(Label. title))]
(when-not no-label
(.setPadding label (Insets. 0.0 5.0 0.0 0.0))
(.setStyle label "-fx-font-weight: bold;")
(.setTextFill label (Color/web sep-color)))
(.setAlignment labeled-separator Pos/CENTER)

    (titled-separator "Here's a Title")