【发布时间】:2018-04-23 23:20:08
【问题描述】:
我有以下方法:
static void display() {
String data = "";
try {
input = new Scanner(file);
while (input.hasNext()) {
data += input.nextLine() + "\n";
}
frame = new JFrame();
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
text = new JTextArea();
text.setForeground(Color.red);
sp = new JScrollPane(text);
text.setFont(new Font("Arial", Font.PLAIN, 20));
text.setOpaque(true);
text.setVisible(true);
text.setEnabled(false);
text.setSize(200, 200);
text.setText(data);
sp.setVisible(true);
frame.add(sp);
frame.validate();
} catch (FileNotFoundException ex) {
Logger.getLogger(Score.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args){
display();
}
现在当我运行文件时,我看到了:
Screenshot showing how the text is a weird blue instead of red
尽可能远离指定的 Color.red。
我做错了什么?为什么前景色没有变成红色?
【问题讨论】:
-
我的猜测是颜色被外观和感觉委托覆盖(可能从外观上看是灵气)
-
我有其他框架和面板工作得很好。只有这个有这个问题。
-
(1-)
Only this one is having this issue.- 然后您已经向自己证明了该方法有效。这段代码和工作代码有什么区别?编程是关于解决问题的。告诉我们有什么区别。不要让我们猜测有什么区别。然后我们可以提供解决方案。 -
没有区别。两个框架的初始化方式相同。它们只是在不同的类中。