【发布时间】:2015-02-28 17:16:15
【问题描述】:
我有这个文本区域在我运行时没有显示的问题。有没有办法让它显示出来。顺便说一句,它是通过扩展画布的类上的游戏循环调用的。
public void render(Graphics g){
Graphics2D g2d = (Graphics2D) g;
if(!initialized)
init();
try {
test.requestFocus();
test.paintAll(g);
test.setText("hi");
test.setBounds(getBounds());
test.printAll(g);
} catch (Exception e) {
e.printStackTrace();
}
g2d.draw(getBounds());
g.drawRect(0, 0, 100, 100);
}
private void init(){
frame.setVisible(false);
initialized = true;
test = new TextArea();
test.setEditable(true);
test.setBounds(getBounds());
test.setBackground(test.getBackground());
test.setForeground(test.getForeground());
frame.add(test);
frame.repaint();
frame.setVisible(true);
System.out.println(test.isVisible());
}
private Rectangle getBounds(){
return new Rectangle(100, 100, 100, 100);
}
我尝试过使用 JTextArea,但它占据了全屏并且不会绑定到矩形。提前感谢您的帮助!
【问题讨论】:
-
你想达到什么目的?要在另一个组件上显示 TextArea,您不需要手动绘制它;只需将其添加到画布旁边的父组件中即可。
标签: java canvas textarea jtextarea game-loop