如何基于用户输入生成JButton?
我想要创建一个Java程序,允许用户在GUI上上传他/她的图片。如果用户使用文件选择器选择多张图片,则窗口将生成具有用户所选文件的按钮。就像在facebook上上传照片一样。
还有其他简单的方法吗?
发布于 2015-01-08 10:39:49
你可以这样做:
JFileChooser jfc = new JFileChooser();
File[] files = jfc.getSelectedFiles();
jfc.setMultiSelectionEnabled(true);
jfc.showOpenDialog(null);
if ( files != null && files.length > 0) {
for ( File file : files ) {
layoutmanager.add(new JButton("Filename")); // Or anything else you want to do with the files/buttons
}
}https://stackoverflow.com/questions/27837696
复制相似问题