为何要求font的大小是浮点类型呢??
我这里有一个很简单的方法改变字体的颜色和大小的代码。我的QQ:283471629
import java.awt.event.ActionListener;import org.eclipse.draw2d.ActionEvent;
import org.eclipse.draw2d.CheckBox;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.*;public class Button2222 { public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(300, 300);
shell.setText("Welcome   to   you !");
Label label = new Label(shell, SWT.NONE);
//label.setsize(50,50);
Color red = new Color(display, 255, 38, 44);
label.setForeground(red);
label.setText("YOUR NAME:");
//label.setBackground(Red); // Font font = new Font (display, "Courier", 30, SWT.NORMAL);
Font font = new Font(display, "Courier", 30, SWT.BOLD); label.setFont(font); Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new RowData(300, SWT.DEFAULT));
Button ok = new Button(shell, SWT.PUSH); Color blue = new Color(display, 0, 0, 225);
ok.setForeground(blue);
ok.setText("Ok"); ok.addSelectionListener(new SelectionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Ok,System accept your information!");
} public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub } public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub } }); ok.setFont(font); Button cancel = new Button(shell, SWT.PUSH);
cancel.setForeground(red);
cancel.setText("Cancel");
// cancel.
cancel.setFont(font);
shell.setDefaultButton(cancel);
shell.setLayout(new RowLayout()); shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
shell.dispose();
red.dispose();
font.dispose();
}
}

解决方案 »

  1.   

    我的目标是大小在plain风格下能够以浮点方式缩放大小,在小程序时,字体采用整数就够了,但比如显示字多时,往往会采用使字体浮点变化的方法来调整字体,现在的问题就是,在plain风格下调整字体浮点大小,字体就使不变,其他风格明显有变化,对此,我迷惑不解,这个应该是java环境的问题,特别是fonts.properties配置的问题,可是,我配置了好几天了,都没能实现,哪个高手能否分析一下为什么??,我有例子代码可以测试刚才的问题,要的人请给mail地址或给我发mail