Is there a method in Java swing that clear a JList and a JTextField?
for example I have开发者_JAVA百科 a string in a Jlist and a string in a JtextField and I want to press a "cancel" button, what method do i need to have in the mouse Listener in order for the Jlist and JtextField to clear?
For JTextField
you can use the setText("");
method. See more here
For JList
you can use the setListData(new Object[0]);
method. If you want the list to stay but only remove the selection you can use the clearSelection()
method. See more here
精彩评论