Change just the font size in SWT

前端 未结 2 1172
闹比i
闹比i 2020-12-16 11:00

I need to use a larger font for one of the labels.

label.setFont( new Font(display,\"Arial\", 14, SWT.BOLD ) );

but obviously Arial is not

2条回答
  •  旧时难觅i
    2020-12-16 11:15

    You can do the following:

    FontData[] fontData = label.getFont().getFontData();
    for(int i = 0; i < fontData.length; ++i)
        fontData[i].setHeight(14);
    
    final Font newFont = new Font(display, fontData);
    label.setFont(newFont);
    
    // Since you created the font, you must dispose it
    label.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            newFont.dispose();
        }
    });
    

提交回复
热议问题