java - ArrayList 中的 JTextField 仅显示最后一个
问题描述
amount = new JTextField(40);
amount.setFont(new Font("Arial", Font.PLAIN, 20));
amount.setBounds(_width / 2 + 25, (_height / 5) * 2 - (_height / 5) / 4, 50, 50);
content.add(amount);
urlBox = new JTextField(40);
ArrayList<JTextField> urlBoxes = new ArrayList<JTextField>();
JButton generate = new JButton("Generate");
generate.setFont(new Font("Arial", Font.PLAIN, 20));
generate.setBounds(_width / 2 + 25 + 55, (_height / 5) * 2 - (_height / 5) / 4, 200, 50);
generate.setBackground(Color.gray);
generate.setForeground(Color.white);
generate.setFocusPainted(false);
generate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
urlBoxes.clear();
for(int i = 0; i < Integer.parseInt(amount.getText()); i++) {
urlBoxes.add(urlBox);
urlBoxes.get(i).setFont(new Font("arial", Font.PLAIN, 20));
}
for(int i = 1; i < Integer.parseInt(amount.getText()) + 1; i++) {
urlBoxes.get(i - 1).setBounds(20, 3 * _height / 10 + 55 * i, _width / 2, 50);
content.add(urlBoxes.get(i - 1));
urlBoxes.get(i - 1).setVisible(true);
System.out.println("Added at " + urlBoxes.get(i - 1).getBounds().y);
}
}
});
content.add(generate);
}
根据System.out.println("Added at " + urlBoxes.get(i - 1).getBounds().y);
我认为他们已经创建并放置在正确的位置,但他们只是没有显示
解决方案
推荐阅读
- jenkins - 在 Jenkins 管道上获取项目的构建大小
- c++ - C++ 关于使用的指针
- arduino - 使用 thingspeak 回话控制 arduino led 时出错
- c++ - c++ 等价于 javascript 或
- javascript - 在javascript中创建json数组
- javascript - 隐藏/显示基于 json 值的复选框
- wordpress - Astra 入门站点导入未通过,它弹出“未找到”并永远保持导入站点继续运行
- wpf - WPF XAML 编辑器总是说 Dictionary with custom key type is not a collection
- sql-server - 如何让 SQL 存储过程与 SELECT 参数一起使用?
- list - 使用单个子句计算列表的任何三个成员的总和是否等于给定值