Real'sHowTo AddThis Feed Button
Custom Search

Bold / Unbold a JLabelTag(s): Swing


JLabel label = new JLabel("I'm bold");
Font font = new Font("Courier", Font.BOLD,12);
label.setFont(font);
You can change the bold attribute after the creation.
Font f = label.getFont();
// bold
label.setFont(f.deriveFont(f.getStyle() | Font.BOLD));

// unbold
label.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD));

// toggle bold
label.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
Thanks to S.Vespo for the bug fix.
blog comments powered by Disqus


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2014
[ home ]