【发布时间】:2013-05-15 10:00:48
【问题描述】:
有人知道如何将JTextField 添加到图形名称bufferstrategy.getDrawGraphics 中吗?
试着把它画成图形,像这样:
private JTextField Input = new JTextField();
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
final Graphics gCommands = bs.getDrawGraphics();
Graphics gCC = bs.getDrawGraphics();
Input.requestFocus();
Input.paint(gCC);
Input.setBounds(800,250, 350,20);
Input.setBorder(BorderFactory.createLineBorder(Color.BLACK, 0));
Input.setEditable(true);
Input.setBackground(getBackground());
Input.setForeground(getForeground());
Input.addKeyListener(key);
但是,即使它显示了,我也无法对其进行编辑。即使Input.setBounds(800,250, 350,20) 也不起作用。上面写的这个方法,在游戏循环中被调用。谁能帮帮我?
【问题讨论】:
-
出了什么问题?您是否收到运行时错误?显示了吗?
-
它显示了,虽然
JTextField不可编辑 -
这个类是 Canvas 吗? JFrame?
-
它扩展了 Canvas,是的
-
Canvas 是一个 AWT 组件。您是否尝试过使用 java.awt.TextField?或者,您可以尝试使用 JTextField 绘制到 JPanel 而不是 Canvas 吗?无论哪种方式,我认为您应该将文本字段添加到支持组件而不是图形。
标签: java graphics render jtextfield bufferstrategy