有人知道如何在图形名称bufferstrategy.getDrawGraphics中添加JTextField吗?尝试将其添加到图形中,如下所示:
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)也不能工作。上面写的这个方法是在gameloop中调用的。有谁可以帮我?
发布于 2013-05-24 10:30:27
在Graphics上绘制组件不会使其成为“活动”组件。组件在变为活动状态之前需要添加到附加到本机对等项的有效容器中。
目前,您要做的唯一一件事就是在图形上下文的表面上生成组件的“橡皮图章”/image。
这其中有一些技巧,因为绘制过程期望组件附加到有效的本机对等体。
首先,你必须准备好场地...
Input.setBounds(800,250, 350,20);
Input.setBorder(BorderFactory.createLineBorder(Color.BLACK, 0));
Input.setEditable(true);
Input.setBackground(getBackground());
Input.setForeground(getForeground());然后你需要把它画出来。字段不会自动重新绘制,同样,这与字段没有附加到本机对等体有关…
Input.printAll(gCC);如果您想要生命组件,则必须将该组件添加到容器中。当使用缓冲策略时,这可能是有问题的。
Swing组件已经有了双缓冲。
https://stackoverflow.com/questions/16656400
复制相似问题