Skip to main content

How to set the font when drawing String in Graphics

2 replies [Last post]
nelsonzou
Offline
Joined: 2013-06-18
Points: 0

Hi, guys

How to set the font when drawing String in Graphics?

Right now I set the size of the font to (Font.SIZE_SMALL, Font.SIZE_LARGE, 48) separately, but the result seems to be no different. Is there anything wrong in the code following:

Form form = new Form();
Layout layout = new CoordinateLayout(640,480);
form.setLayout(layout);

Label labTmp = new Label();
labTmp.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
labTmp.setText("String Text");
Container conTmper = new Container();
conTmper.addComponent(labTmp);
conTmper.setX(300);
conTmper.setY(300);
conTmper.getStyle().setBgTransparency(100);
form.addComponent(conTmper);

Label labTmp1 = new Label();
labTmp1.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
labTmp1.setText("String Text");
Container conTmper1 = new Container();
conTmper1.addComponent(labTmp1);
conTmper1.setX(300);
conTmper1.setY(320);
conTmper1.getStyle().setBgTransparency(100);
form.addComponent(conTmper1);

Label labTmp2 = new Label();
labTmp2.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, 48));
labTmp2.setText("String Text");
Container conTmper2 = new Container();
conTmper2.addComponent(labTmp2);
conTmper2.setX(300);
conTmper2.setY(340);
conTmper2.getStyle().setBgTransparency(100);
form.addComponent(conTmper2);

form.show();

Thanks.
Nelson

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nelsonzou
Offline
Joined: 2013-06-18
Points: 0

Sorry, the code is about Label, but it's still no different. The code of drawString in Graphics is as following:

public void drawCircle(int angle) {
Image imgBg = ComponentGenerator.imageCreate("BgTransperancy.png", "images");
imgBg.scale(200, 200);
Graphics graphBg= imgBg.getGraphics();
graphBg.setColor(255);
Font fontCurrentTmp = graphBg.getFont();
graphBg.setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
graphBg.drawString("Circle Test", 0, 0);

graphBg.setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, 48));
}

Thanks.

nelsonzou
Offline
Joined: 2013-06-18
Points: 0

Sorry, the code is about Label, but it's still no different. The code of drawString in Graphics is as following:

public void drawCircle(int angle) {
Image imgBg = ComponentGenerator.imageCreate("BgTransperancy.png", "images");
imgBg.scale(200, 200);
Graphics graphBg= imgBg.getGraphics();
graphBg.setColor(255);
Font fontCurrentTmp = graphBg.getFont();
graphBg.setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
graphBg.drawString("Circle Test", 0, 0);

graphBg.setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, 48));
}

Thanks.