Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added grid-layout

  • Loading branch information...
commit 2286b4fb2326f7357609528661dc58b1a84c4e86 1 parent e4e06e9
@odyssomay authored
Showing with 17 additions and 1 deletion.
  1. +17 −1 src/Hafni/swing/layout.clj
View
18 src/Hafni/swing/layout.clj
@@ -2,7 +2,7 @@
(:use (Hafni utils arrow event)
(Hafni.swing component))
(:import (javax.swing BoxLayout JPanel)
- (java.awt BorderLayout CardLayout FlowLayout)))
+ (java.awt BorderLayout CardLayout FlowLayout GridLayout)))
(defn border-layout
"Create a BorderLayout
@@ -85,3 +85,19 @@ Fields:
"right" FlowLayout/RIGHT
(throw (Exception. ""))))}]
(init-comp cont arrs nil opts)))
+
+(defn grid-layout
+ "Create a GridLayout
+Fields:
+ :content - content of layout | [Component]
+ :hgap - Horizontal gap between components | Int
+ :vgap - Vertical gap between components | Int"
+ [rows cols & options]
+ (let [opts (parse-options options)
+ layout (GridLayout. rows cols)
+ cont (JPanel. layout)
+ arrs {:content (fn [coll]
+ (dorun (map #(.add cont (component %)) coll)))
+ :hgap #(.setHgap layout %)
+ :vgap #(.setVgap layout %)}]
+ (init-comp cont arrs nil opts)))
Please sign in to comment.
Something went wrong with that request. Please try again.