Home

Awesome

abcl-jazz

A simple example on how to use Swing UI components from Common Lisp (using ABCL)

This, hopefully, sometime, will become a full featured UI library. Or not.

Screenshot

Prior Art

Snow: Nice, but too verbose, and too detached from the swing classes.

Reason

Why?

Because desktop "native" apps never died. And using Electron is immoral.

Instead of Electron, let's use:

Note: Not only is swing programming under JAZZ easier than Java, it is also easier, for example, than under Jython (Python for the JVM)

Usage

Requires ABCL. So, load ABCL. I used ABCL 1.5.0

(require) :abcl-contrib, and :jss

Useful to do (setf jss:*muffle-warnings* nil) as well.

Then load swing.lisp and try the examples in swing-test.lisp. This creates no packages.

Example(s)

See swing-test.lisp

This includes three examples:

Pasted from there: A "notepad"-like application where you just edit text and the window shows cursor position. Includes menu bars. (Barely implemented, of course)

;; Partial rewrite of https://www.javatpoint.com/notepad
(defun notepad-app ()
  (let*
      ((f
         (frame "Notepad App" 640 480))
       (status-bar
         (label "||       Ln 1, Col 1  " +align-right+))
       (ta                              ;textarea
         (textarea "" 30 60))
       (not-implemented
         (lambda (e)
           (declare (ignore e))
           (show-warning-message f "Not Implemented"))))
    ;; Here we go...
    (add-using-borderlayout f
                            :center (scrollpane ta)
                            :south status-bar
                            :east (label "   ")
                            :west (label "   "))
    (pack f)
                                        

    ;; menu bar
    (set-menu-bar f 
                  (list 
                   (menu "File" 
                         (list 
                          (menuitem "New" not-implemented)
                          (menuitem "Open" not-implemented)
                          (menuitem "Save" not-implemented)
                          (menuitem "Save as..." not-implemented)))
                   (menu "Edit" 
                         (list 
                          (menuitem "Undo!" not-implemented)
                          (separator)
                          (menuitem "Cut" not-implemented)
                          (menuitem "Copy" not-implemented)
                          (menuitem "Paste" not-implemented)
                          (menuitem "Delete" not-implemented)
                          (separator)
                          (menuitem "Select all" not-implemented)
                          ))
                   (menu "Format" ())
                   (menu "View" ())
                   (menu "Help" ())))

    ;; right-click popup menu
    (add-popupmenu-to-container
     ta                                 ;to text area 
     (popupmenu "Right click menu" 
                (list
                 (menuitem "Undo!" not-implemented)
                 (separator)
                 (menuitem "Cut")
                 (menuitem "Copy")
                 (menuitem "Paste"))))

    ;; caretlistener for text area
    (add-caretlistener ta
                       (lambda (e)
                         (declare (ignore e))
                         (let* ((pos (#"getCaretPosition" ta))
                                (line (#"getLineOfOffset" ta pos))
                                (col (- pos (#"getLineStartOffset" ta line))))
                           (#"setText" status-bar
                                       (format nil "||   Ln ~D, Col ~D"
                                               line
                                               col)))))
    (set-visible f)))

The concatenate-app on concatenar.lisp shows how easy is using the BorderLayout from Lisp, compared to doing it from Java. This one is in spanish, because I speak very... very fluent spanish. Todo está bien chévere. Bien chévere. (Stevie Wonder, "Don't you worry about a thing").

Stevie Wonder, needless to say, is a funky drummer too.

Philosophy

If this example evolves into a lib, this would be my preferred philosophy:

Author

Defunkydrummer

License

MIT