[fxruby-users] How can you bold the text in a label?

Joey Kinsella jkinsella at ancillaryservices.com
Thu Apr 15 13:04:07 EDT 2010

There are definitely better ways of doing this, but here is a basic example:

Begin code

#! /usr/bin/env ruby

require 'rubygems'
require 'fox16'

include Fox

class SimpleWindow < FXMainWindow
  def initialize(app)
    super(app, "My Simple Window", :opts => DECOR_ALL,
      :width => 640, :height => 480)


  def draw_widgets()
    label = FXLabel.new(self, "This is my label that is normal.")
    label.font = FXFont.new(getApp(), select_font())

    label2 = FXLabel.new(self, "This is my label that is bold.")
    label2.font = FXFont.new(getApp(), select_font(FONTWEIGHT_BOLD))


  def select_font(weight = FONTWEIGHT_NORMAL)
    f = FXFontDesc.new()
    f.face = "Helvetica"
    f.flags = 0
    f.setwidth = FONTSETWIDTH_WIDE
    f.size = 100
    f.weight = weight

    return (f)

  def create()

if(__FILE__ == $0)
  app = FXApp.new("Example", "Example")
  win = SimpleWindow.new(app)


End Code...

I Hope this helps!

On Thu, Apr 15, 2010 at 12:30 PM, Paul Carvalho <tester.paul at gmail.com>wrote:

> I'm not at my development computer right now so I can't tell you the exact
> code I tried, but I can say that, yes, I did try to use a nil/empty string
> font face and Ruby choked on it -- didn't like it.
> I tried "system" as a font face and that *really* didn't do what I wanted
> either! =)
> I entered "arial" and then the one label font changed - I had forgotten
> that the default system font is not Arial.  So the one label really stands
> out now because it's a totally different font.. which is not what I want.
> I don't want to hard-code a font that is different from the system font,
> especially if the app will run on different platforms and I don't know what
> the default fonts will be.
> I can try some other variations tonight.  I've already spent over 4 hours
> on this and haven't gotten it to work.  Maybe I just needed a break to see
> something that I've missed.
> I thought it would be something that would have come up by now.. I've seen
> lots of apps where a label is bolded to indicate a required field.  I just
> haven't found any FXRuby examples of this *without* also specifying the font
> at the same time.
> Cheers.  P.
> 2010/4/15 Bartosz Dziewoński :
>> Have you tried to use nil/empty string font face and use font style
>> hint "System"? Or try any font together with the hint?
>> I haven't tried it myself, but according to docs it might work.
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users

If you are not the intended recipient, you are hereby notified
that any dissemination, distribution, copying or other use of
this communication is strictly prohibited.  If you have
received this communication in error, please notify us

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/6b827cdc/attachment.html>

More information about the fxruby-users mailing list