用 setForeground方法 public class Testsetcolor { public static void main(String[] args) { Frame f = new Frame("testSetColor"); f.setBounds(300, 300, 400, 300);
谢谢,可能你们还没有理解我的意思。我的需求是:现在有一个文本框和一个按钮,我在文本框中填入aaa,点击按钮后,会弹出一个提示对话框(JOptionPane.showMessageDialog(null,文本框输入的类容(aaa)+"is not allowed to input!"))显示:aaa is not allowed to input!.其中文本框中的颜色默认时黑色,而要求这个提示对话框中的aaa需要显示为红色,其他的字还是黑色,明白了吗?请高手解答。谢谢!
用 setForeground方法 public class Testsetcolor {
public static void main(String[] args) {
Frame f = new Frame("testSetColor");
f.setBounds(300, 300, 400, 300);
Label l1 = new Label("TestColor");
l1.setForeground(Color.RED); //字体颜色设置为红色
f.add(l1);
f.setVisible(true);
} }