这是一个小型代码,应该显示一个textarea并显示我输入的内容。但我不知道为什么它不显示文本。当我按住任意键时,水平滚动条移动,意味着有东西进入,但没有任何显示。 我使用JDK 1.8并在Windows 7 64位上使用记事本进行编辑。Java8 - 文本不会显示在TextArea中
public class tarea
{
public static void main (String[] args)
{
Frame f = new Frame("My Frame");
f.setLocation(100, 100);
f.setSize(500, 500);
f.setLayout(null);
f.setBackground(Color.BLACK);
f.setTitle("My area");
TextArea ta = new TextArea();
ta.setBounds(10, 10, 400, 400);
f.add(ta);
f.setVisible(true);
}
}
为什么你还在使用AWT?它被多年前的Swing替代 – msrd0 2014-09-27 10:44:36
只需删除这两行:'f.setLayout(null);'和'ta.setBounds(10,10,400,400);'。否则,你会得到你所要求的... – Holger 2014-09-27 12:44:31