我在表单上添加了一个名为 的btnBar
容器boxlayout(x-axis)
。容器有 4 个自定义类的按钮,MyButton
它们从Button
自身扩展。当我添加actionlistener
到容器中的一个按钮时,每个按钮都会调用它。即使该actionevent.getsource.gettext
方法返回相同的值,而与焦点无关。我已经通过数组添加了按钮,我尝试使用的是这样的:
btns[0].addActionListener(......)
我哪里错了?
我在表单上添加了一个名为 的btnBar
容器boxlayout(x-axis)
。容器有 4 个自定义类的按钮,MyButton
它们从Button
自身扩展。当我添加actionlistener
到容器中的一个按钮时,每个按钮都会调用它。即使该actionevent.getsource.gettext
方法返回相同的值,而与焦点无关。我已经通过数组添加了按钮,我尝试使用的是这样的:
btns[0].addActionListener(......)
我哪里错了?
got is solved buddies...actually was using setfocus() to traverse within the btnBar on buttons...but needed to use setFocused() method of form too....after setFocus()....dnt hammer ur brains now....
You must never use setFocus
, you should use setFocusable
to toggle focusability and requestFocus
to get the focus to a specific component.
You should also migrate to Codename One, since LWUIT is pretty much unmaintained.