我有一个带有按钮的数组:
JButton[] commandButtons = {
new JButton("Add Chair"),
new JButton("Add Table"),
new JButton("Add Desk"),
new JButton("Clear All"),
new JButton("Total Price"),
new JButton("Save"),
new JButton("Load"),
new JButton("Summary")
};
我想将它们全部放在面板中,但它只显示最后一个按钮。 因此,如果有人知道如何解决它或有建议,那就太好了。
此外,我不知道如何将 for 循环作为 foreach 进行。
for(int i=0; i<commandButtons.length; i++)
{
westPanel.add(commandButtons[i]);
commandButtons[i].addActionListener(this);
}
最佳答案
在westPanel JPanel上设置一个FlowLayout管理器,它们都会显示出来。
关于java - 不显示所有按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9757724/