How do I change font size

70 views
Skip to first unread message

Noobie

unread,
Jun 18, 2015, 5:51:11 AM6/18/15
to codenameone...@googlegroups.com
Hallo,

I'm working with eclipse on Windows 7 and usually use the default iphone simulator. I've encountered a seemingly simple problem, I wasn't able to solve yet. I tried, really.

      How can I change the size of the text of a button?

I'm talking about the system font, doing it manually in the code, really basic. It worked for:

      button.getStyle().setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE));

the solution I got from this forum, but it destroyed the rest of the looks of the button. Also it was still too small for my purpose.
I already tried to download a ttf, too, but it doesn't seem to be accepted, through:

      if(Font.isTrueTypeFileSupported()) {
            Font myFont = Font.createTrueTypeFont("HotSweat", "HotSweat.ttf");
            myFont = myFont.derive(36, Font.STYLE_PLAIN);
      }

Greets!

Shai Almog

unread,
Jun 18, 2015, 10:29:24 AM6/18/15
to codenameone...@googlegroups.com, beru...@gmail.com, beru...@gmail.com
Hi,
first you need to use getUnselectedStyle(), getSelectedStyle() and in the case of button also getPressedStyle(). Never use getStyle().
Personally I'd just use setUIID(...) and define the style I want (and the font) in the designer which is simpler.

What isn't working for you with the ttf? Did you place the file in the root of the src directory?

beru...@gmail.com

unread,
Jun 18, 2015, 11:59:43 AM6/18/15
to codenameone...@googlegroups.com, beru...@gmail.com
Okay, I played around a little bit and now it is working somehow, both with system font and external ttf. But I see, I will have to use the getUnselected... etc., thanks.
Can you tell me how to manipulate existing components, like the button, in the gui builder? I started off the manual hello world. So I wrote button.setUIID("specialbutton") in the code, but how can i access this element now in the builder, where do I find it? (I open the builder by clicking on theme.res, is that right?) And how can I make sure, the font size attribute is just added to the default theme button look I use, so I don't have to begin at zero and adjust that, too.

Shai Almog

unread,
Jun 18, 2015, 11:17:26 PM6/18/15
to codenameone...@googlegroups.com, beru...@gmail.com, beru...@gmail.com
Reply all
Reply to author
Forward
0 new messages