为何要求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();
}
}
我这里有一个很简单的方法改变字体的颜色和大小的代码。我的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();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货