Setting the font size

626 views
Skip to first unread message

Cecil Westerhof

unread,
Oct 5, 2016, 4:47:14 AM10/5/16
to clo...@googlegroups.com
I already asked it on Clojure-seesaw, but the last three months there
has been no activity there. So I ask it here also.

Some time ago I wrote a Clojure program that uses SeeSaw. I just
bought a high resolution monitor and now I cannot read the text in my
JFrames anymore. How can I increase the default font size?

I create the frames like:
(let [
^JFrame
other-frm (frame :title "Other" :on-close
:hide :resizable? false)

I now generate buttons like:
^JButton
all-authors (button :text "All Authors"
:font {:size 25}
:listen [:action (fn [e] (show-all-authors))])

But I have to set the font for every label in this way.

At another part I have:
(grid-bag-layout
search-panel
:fill :HORIZONTAL
:ipadx 8
:ipady 4
:gridy i
:gridx 0 ^JLabel (label description)
:gridx 1 ^JTextField
(text :columns 40
:listen
[:action (fn [e]
(let [
search-str (text e)
]
(when (not (empty? search-str))
(function search-str))))
]))))

At the moment I do not know how to set the font there.

Is there also a way to increase/decrease the fontsize in the whole
application. I now have amiddle and high resolution screen. It would
be nice if when I put things on the other monitor, the fonts would
scale.

--
Cecil Westerhof

Sanel Zukan

unread,
Oct 5, 2016, 7:22:03 AM10/5/16
to Clojure
Hi Cecil,

Setting fonts under Seesaw isn't the most intuitive option, so you'd
have to dig into Swing core for this and investigate
java.swing.UIManager documentation.

Here is a function that I often use in my applications:

(defn set-font
  "Set default font for the whole Swing application. Make sure
to call it before UI was shown."
  [name size]
  (let [res  (FontUIResource. name Font/PLAIN size)
        what ["Button.font" "ToggleButton.font"
              "RadioButton.font" "CheckBox.font"
              "ColorChooser.font" "ComboBox.font"
              "Label.font" "List.font"
              "MenuBar.font" "MenuItem.font"
              "RadioButtonMenuItem.font"
              "CheckBoxMenuItem.font" "Menu.font"
              "PopupMenu.font" "OptionPane.font"
              "Panel.font" "ProgressBar.font"
              "ScrollPane.font" "Viewport.font"
              "TabbedPane.font" "Table.font"
              "TableHeader.font" "TextField.font"
              "PasswordField.font" "TextArea.font"
              "TextPane.font" "EditorPane.font"
              "TitledBorder.font" "ToolBar.font"
              "ToolTip.font" "Tree.font"]]
    (doseq [key what]
      (UIManager/put key res))))

I use it like:

(defn runner []
  (seesaw/native!)
  (seesaw/invoke-later
   (set-font "Sans Serif" 11)
   (seesaw/show! <here-comes-form-builder>)))

Best,
Sanel

Cecil Westerhof

unread,
Oct 6, 2016, 3:22:19 AM10/6/16
to clo...@googlegroups.com
Thanks that works. I should put it always on my high-resolution screen then.

Two points:
When using:
(seesaw/invoke-later
I get:
Exception in thread "main" java.lang.RuntimeException: No such
namespace: seesaw

What do I need to do to get rid of this?

Is it possible to increase the font in the title from the window?
Probably not, because I think that is done by the Operating System.
But maybe I am wrong.

Sanel Zukan

unread,
Oct 6, 2016, 6:08:56 AM10/6/16
to Cecil Westerhof, clo...@googlegroups.com
Cecil Westerhof <cldwes...@gmail.com> writes:
> Two points:
> When using:
> (seesaw/invoke-later
> I get:
> Exception in thread "main" java.lang.RuntimeException: No such
> namespace: seesaw
>
> What do I need to do to get rid of this?

(require '[seesaw.core :as seesaw])

> Is it possible to increase the font in the title from the window?
> Probably not, because I think that is done by the Operating System.
> But maybe I am wrong.

No; this is OS specific and the only safe option is to manually draw
frame titlebar and borders, handling all mouse/keyboard/DnD events by
yourself.

Other option is to go with frameworks that has this feature, like WebLaF
(http://weblookandfeel.com/).

Best,
Sanel

Cecil Westerhof

unread,
Oct 6, 2016, 6:32:05 AM10/6/16
to clo...@googlegroups.com
2016-10-06 12:08 GMT+02:00 Sanel Zukan <san...@gmail.com>:
> Cecil Westerhof <cldwes...@gmail.com> writes:
>> Two points:
>> When using:
>> (seesaw/invoke-later
>> I get:
>> Exception in thread "main" java.lang.RuntimeException: No such
>> namespace: seesaw
>>
>> What do I need to do to get rid of this?
>
> (require '[seesaw.core :as seesaw])

I saw that I already had:
(use 'seesaw.core)
and called:
(invoke-later

So I changed your call also into (invoke-later. Is this OK, or is
there a reason to do it your way?


> No; this is OS specific and the only safe option is to manually draw
> frame titlebar and borders, handling all mouse/keyboard/DnD events by
> yourself.
>
> Other option is to go with frameworks that has this feature, like WebLaF
> (http://weblookandfeel.com/).

Well, for the moment I accept it then.

--
Cecil Westerhof

Sanel Zukan

unread,
Oct 6, 2016, 8:33:38 AM10/6/16
to Cecil Westerhof, clo...@googlegroups.com
Cecil Westerhof <cldwes...@gmail.com> writes:
> I saw that I already had:
> (use 'seesaw.core)
> and called:
> (invoke-later
>
> So I changed your call also into (invoke-later. Is this OK, or is
> there a reason to do it your way?

That is fine. It is more idiomatic to use 'require' to avoid namespace
conflicts, as explained on http://stackoverflow.com/questions/871997/difference-between-use-and-require.

Best,
Sanel

Cecil Westerhof

unread,
Oct 6, 2016, 12:27:14 PM10/6/16
to clo...@googlegroups.com
OK, it was a little work, but I use the require variant now. I have:
(ns quotes.core
(:require
[clj-time.local :as l]
[clojure.java.jdbc :as jdbc]
[clojure.pprint :refer [pprint print-table]]
[clojure.string :refer [lower-case]]
[seesaw.core :as seesaw]
[yesql.core :refer [defquery defqueries]]
))

(import '(javax.swing JButton JCheckBox JDialog JFrame JLabel JOptionPane JPanel
JTextField UIManager plaf.FontUIResource)
'(java.awt Font GridBagLayout GridBagConstraints))

--
Cecil Westerhof
Reply all
Reply to author
Forward
0 new messages