1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
public class JRenameFile extends JFrame {
private String path;
private JTable table;
private JScrollPane jscroll;
public void setPath(String path){
this.path = path;
}
public String getPath(){
return this.path;
}
public static Object[][] getListOfFileName(String path){
File repertoire = new File(path);
File[] list = repertoire.listFiles();
Object[][] donnees = new Object[list.length][2];
for(int i = 0 ; i < list.length ; i++){
donnees[i][0] = list[i].getName();
donnees[i][1] = "";
}
return donnees;
}
public static String[] getColumnNames(){
String[] columnNames = {"Nom du fichier","Renommer en :"};
return columnNames;
}
public JRenameFile(){
jscroll = new JScrollPane();
table = new JTable();
jscroll.setViewportView(table);
setTitle("Renommer simplement vos fichiers");
setSize(800,600);
GridBagLayout grid = new GridBagLayout();
getContentPane().setLayout(grid);
GridBagConstraints c1 = new GridBagConstraints();
c1.gridx = 0;
c1.gridy = 0;
c1.anchor = GridBagConstraints.EAST;
getContentPane().add(jscroll,c1);
JMenuBar menu = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem load = new JMenuItem("load");
load.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showOpenDialog(JRenameFile.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
table = new JTable(getListOfFileName(fc.getSelectedFile().getPath()),getColumnNames());
jscroll.add(table);
table.revalidate();
table.repaint();
jscroll.revalidate();
jscroll.repaint();
}
}
});
file.add(load);
menu.add(file);
setJMenuBar(menu);
}
public static void main(String[] args){
JRenameFile frame = new JRenameFile();
frame.setVisible(true);
}
} |
Partager