Clearing contents of TextField using setText does not work in AWT

旧城冷巷雨未停 提交于 2019-11-29 15:21:58

I see the problem as well using Java 8u11. I seem to remember this being filed as a known bug, but I can't seem to find it now.

A solution that works for me is to add an intermediate step:

public void actionPerformed(ActionEvent e) {
   tf.setText(" ");  
   tf.setText("");
}

I'm not sure why this is necessary, I think it's a bug with the setText() function specifically ignoring empty Strings. If somebody finds the filed bug there would be more information there.

Add space in setText(" ") in function and see if it works. But there after there will be one space.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!