Saturday, June 11, 2022

Nimbus

The Nimbus look and feel is nice and different.
(import javax.swing.UIManager)
(import javax.swing.JFrame)
(import javax.swing.JTextField)
(import javax.swing.JButton)
(import javax.swing.JPanel)
(import javax.swing.JLabel)
(import javax.swing.BoxLayout)
(import java.awt.Component)
(import java.awt.GridBagLayout)

(defn main
  []
  
  (UIManager/setLookAndFeel "javax.swing.plaf.nimbus.NimbusLookAndFeel")
  
  (let [frame (JFrame. "Swing viewer")
        container (JPanel.)
        first-panel (JPanel.)
        second-panel (JPanel.)
        third-panel (JPanel.)] 
    (.setLayout frame (GridBagLayout.))
    (.setLayout container (BoxLayout. container BoxLayout/Y_AXIS))
  
    (.add first-panel (JLabel. "Source"))
    (.add first-panel (JTextField. (int 20)))
    (.setAlignmentX first-panel Component/LEFT_ALIGNMENT)
    (.add container first-panel)
  
    (.add second-panel (JLabel. "Target"))
    (.add second-panel (JTextField. (int 20)))
    (.setAlignmentX second-panel Component/LEFT_ALIGNMENT)
    (.add container second-panel)    

    (.add third-panel (JButton. "Close"))
    (.add third-panel (JButton. "Submit"))
    (.setAlignmentX third-panel Component/LEFT_ALIGNMENT)
    (.add container third-panel)   
    
    (.setSize frame 400 200)
    (.add frame container)
    (.setVisible frame true)))
  
(main)

Look at the result produced after calling the UIManager: The buttons have a different look and feel then the other cases I am used to. If you manually set the look and feel with the UIManager, the only thing is that the resulting application will not look native anymore. The pluggable look and feel is one of the nice features of Swing that wasn't available before in AWT.

No comments:

Post a Comment