Java 在for循环中创建jbutton之后删除它们
在for循环中创建对象后,如何删除Java 在for循环中创建jbutton之后删除它们,java,for-loop,jbutton,Java,For Loop,Jbutton,在for循环中创建对象后,如何删除JButton对象 我已经在for循环中创建了按钮对象,我想删除它们 之后,但这可能吗 我有以下算法: For each one of the elements in the ArrayList Create a JButton(text) , where text is the current value for the specific element add it to the GridLayout Java示例代码: ArrayList
JButton
对象
我已经在for循环中创建了按钮对象,我想删除它们
之后,但这可能吗
我有以下算法:
For each one of the elements in the ArrayList
Create a JButton(text) , where text is the current value for the specific element
add it to the GridLayout
Java示例代码:
ArrayList AL;
for(int i = 0; i < AL.size() - 1 ; i++) {
JButton JB = new JButton(get(i)); //add the text in JButton
grid.add(JB);
}
arraylistal;
对于(int i=0;i
之后我如何移除它们?
由于我正在动态创建它们,是否可以删除它们?您可以稍后通过将
JButton
引用存储在数组中来删除它们。只需遍历该数组或列表并删除条目。您可以稍后通过将JButton
引用存储在数组中来删除它们。只需遍历该数组或列表并删除条目。您可以扫描添加到的对象的子对象并将其删除,也可以在创建它们时保留它们的列表,然后扫描列表以删除它们。您可以扫描添加到的对象的子对象并将其删除它们在那里,或者您可以在创建它们时保留它们的列表,然后扫描列表以删除它们。这是有效的,因为我创建了ArrayList=new ArrayList(),存储了对象引用,之后我遍历了数组并删除了条目。感谢这是有效的,因为我创建了ArrayList=new ArrayList(),我存储了对象引用,然后遍历了数组并删除了条目。谢谢