JFileChooser jfc = null; File se = jfc.getSelectedFile();
Code Java :
JFileChooser jfc = null; File se = jfc.getSelectedFile();
Pour le jar, il n'y a pas de souci : si le chemin existe ça va marcher (enfin, là avec un chemin pareil, ça ne marchera que sur ton ordinateur). Il est préférable de ne pas spécifier le dossier (ou alors tu le mets dans un fichier de propriétés).
choix.setCurrentDirectory(new File("../DVD 3A INFORMATIQUE/200 logiciels"));
private JFileChooser jfc;
choix.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
choix.setCurrentDirectory(new File("../DVD 3A INFORMATIQUE/200 logiciels"));
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionat java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
10:12.35 1[dbg] In DllGetClassObject 10:12.35 2[dbg] CShellExtClassFactory::CShellExtClassFactory() 10:12.35 3[dbg] CShellExtClassFactory::QueryInterface() 10:12.35 4[dbg] CShellExtClassFactory::CreateInstance() 10:12.35 5[dbg] CShellExt::CShellExt() 10:12.35 6[dbg] Looping before Zumo is running 10:12.35 7[dbg] Drive not mounted 10:12.35 8[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 9[dbg] CShellExt::AddRef() 10:12.35 10[dbg] CShellExt::AddRef() 10:12.35 11[dbg] CShellExt::Release() 10:12.35 12[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 13[dbg] CShellExt::AddRef() 10:12.35 14[dbg] CShellExt::Release() 10:12.35 15[dbg] Entering CShellExt::GetOverlayInfo 10:12.35 16[dbg] Icon path: C:\Program Files (x86)\Hewlett-Packard\HP CloudDrive\icons\deflated.ico 10:12.35 17[dbg] Exiting CShellExt::GetOverlayInfo successfully. 10:12.35 18[dbg] Time to execute: 0ms 10:12.35 19[dbg] Entering CShellExt::GetPriority 10:12.35 20[dbg] Exiting CShellExt::GetPriority 10:12.35 21[dbg] In DllGetClassObject 10:12.35 22[dbg] CShellExtClassFactory::CShellExtClassFactory() 10:12.35 23[dbg] CShellExtClassFactory::QueryInterface() 10:12.35 24[dbg] CShellExtClassFactory::CreateInstance() 10:12.35 25[dbg] CShellExt::CShellExt() 10:12.35 26[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 27[dbg] CShellExt::AddRef() 10:12.35 28[dbg] CShellExt::AddRef() 10:12.35 29[dbg] CShellExt::Release() 10:12.35 30[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 31[dbg] CShellExt::AddRef() 10:12.35 32[dbg] CShellExt::Release() 10:12.35 33[dbg] Entering CShellExt::GetOverlayInfo 10:12.35 34[dbg] Icon path: C:\Program Files (x86)\Hewlett-Packard\HP CloudDrive\icons\download.ico 10:12.35 35[dbg] Exiting CShellExt::GetOverlayInfo successfully. 10:12.35 36[dbg] Time to execute: 0ms 10:12.35 37[dbg] Entering CShellExt::GetPriority 10:12.35 38[dbg] Exiting CShellExt::GetPriority 10:12.35 39[dbg] In DllGetClassObject 10:12.35 40[dbg] CShellExtClassFactory::CShellExtClassFactory() 10:12.35 41[dbg] CShellExtClassFactory::QueryInterface() 10:12.35 42[dbg] CShellExtClassFactory::CreateInstance() 10:12.35 43[dbg] CShellExt::CShellExt() 10:12.35 44[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 45[dbg] CShellExt::AddRef() 10:12.35 46[dbg] CShellExt::AddRef() 10:12.35 47[dbg] CShellExt::Release() 10:12.35 48[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 49[dbg] CShellExt::AddRef() 10:12.35 50[dbg] CShellExt::Release() 10:12.35 51[dbg] Entering CShellExt::GetOverlayInfo 10:12.35 52[dbg] Icon path: C:\Program Files (x86)\Hewlett-Packard\HP CloudDrive\icons\share.ico 10:12.35 53[dbg] Exiting CShellExt::GetOverlayInfo successfully. 10:12.35 54[dbg] Time to execute: 0ms 10:12.35 55[dbg] Entering CShellExt::GetPriority 10:12.35 56[dbg] Exiting CShellExt::GetPriority 10:12.35 57[dbg] In DllGetClassObject 10:12.35 58[dbg] CShellExtClassFactory::CShellExtClassFactory() 10:12.35 59[dbg] CShellExtClassFactory::QueryInterface() 10:12.35 60[dbg] CShellExtClassFactory::CreateInstance() 10:12.35 61[dbg] CShellExt::CShellExt() 10:12.35 62[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 63[dbg] CShellExt::AddRef() 10:12.35 64[dbg] CShellExt::AddRef() 10:12.35 65[dbg] CShellExt::Release() 10:12.35 66[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 67[dbg] CShellExt::AddRef() 10:12.35 68[dbg] CShellExt::Release() 10:12.35 69[dbg] Entering CShellExt::GetOverlayInfo 10:12.35 70[dbg] Icon path: C:\Program Files (x86)\Hewlett-Packard\HP CloudDrive\icons\upload.ico 10:12.35 71[dbg] Exiting CShellExt::GetOverlayInfo successfully. 10:12.35 72[dbg] Time to execute: 0ms 10:12.35 73[dbg] Entering CShellExt::GetPriority 10:12.35 74[dbg] Exiting CShellExt::GetPriority 10:12.35 75[dbg] In DllGetClassObject 10:12.35 76[dbg] CShellExtClassFactory::CShellExtClassFactory() 10:12.35 77[dbg] CShellExtClassFactory::QueryInterface() 10:12.35 78[dbg] CShellExtClassFactory::CreateInstance() 10:12.35 79[dbg] CShellExt::CShellExt() 10:12.35 80[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 81[dbg] CShellExt::AddRef() 10:12.35 82[dbg] CShellExt::AddRef() 10:12.35 83[dbg] CShellExt::Release() 10:12.35 84[dbg] CShellExt::QueryInterface()==>IID_IShellIconOverlayIdentifier 10:12.35 85[dbg] CShellExt::AddRef() 10:12.35 86[dbg] CShellExt::Release() 10:12.35 87[dbg] Entering CShellExt::GetOverlayInfo 10:12.35 88[dbg] Icon path: C:\Program Files (x86)\Hewlett-Packard\HP CloudDrive\icons\fw.ico 10:12.35 89[dbg] Exiting CShellExt::GetOverlayInfo successfully. 10:12.35 90[dbg] Time to execute: 0ms 10:12.35 91[dbg] Entering CShellExt::GetPriority 10:12.35 92[dbg] Exiting CShellExt::GetPriority 10:12.40 93[dbg] Looping before Zumo is running 10:12.40 94[dbg] Drive not mounted 10:12.45 95[dbg] Looping before Zumo is running 10:12.45 96[dbg] Drive not mounted 10:12.50 97[dbg] Looping before Zumo is running 10:12.50 98[dbg] Drive not mounted 10:12.55 99[dbg] Looping before Zumo is running 10:12.55 100[dbg] Drive not mounted 10:13.00 101[dbg] Looping before Zumo is running 10:13.00 102[dbg] Drive not mounted 10:13.05 103[dbg] Looping before Zumo is running 10:13.05 104[dbg] Drive not mounted 10:13.10 105[dbg] Looping before Zumo is running 10:13.10 106[dbg] Drive not mounted 10:13.15 107[dbg] Looping before Zumo is running 10:13.15 108[dbg] Drive not mounted 10:13.20 109[dbg] Looping before Zumo is running 10:13.20 110[dbg] Drive not mounted 10:13.25 111[dbg] Looping before Zumo is running 10:13.25 112[dbg] Drive not mounted 10:13.30 113[dbg] Looping before Zumo is running 10:13.30 114[dbg] Drive not mounted 10:13.35 115[dbg] Looping before Zumo is running 10:13.35 116[dbg] Drive not mounted 10:13.40 117[dbg] Looping before Zumo is running 10:13.40 118[dbg] Drive not mounted 10:13.45 119[dbg] Looping before Zumo is running 10:13.45 120[dbg] Drive not mounted 10:13.50 121[dbg] Looping before Zumo is running 10:13.50 122[dbg] Drive not mounted 10:13.55 123[dbg] Looping before Zumo is running 10:13.55 124[dbg] Drive not mounted 10:14.00 125[dbg] Looping before Zumo is running 10:14.00 126[dbg] Drive not mounted 10:14.05 127[dbg] Looping before Zumo is running 10:14.05 128[dbg] Drive not mounted 10:14.10 129[dbg] Looping before Zumo is running 10:14.10 130[dbg] Drive not mounted 10:14.15 131[dbg] Looping before Zumo is running 10:14.15 132[dbg] Drive not mounted 10:14.20 133[dbg] Looping before Zumo is running 10:14.20 134[dbg] Drive not mounted 10:14.25 135[dbg] Looping before Zumo is running 10:14.25 136[dbg] Drive not mounted 10:14.30 137[dbg] Looping before Zumo is running 10:14.30 138[dbg] Drive not mounted 10:14.35 139[dbg] Looping before Zumo is running 10:14.35 140[dbg] Drive not mounted 10:14.40 141[dbg] Looping before Zumo is running 10:14.40 142[dbg] Drive not mounted 10:14.45 143[dbg] Looping before Zumo is running 10:14.45 144[dbg] Drive not mounted 10:14.50 145[dbg] Looping before Zumo is running 10:14.50 146[dbg] Drive not mounted 10:14.55 147[dbg] Looping before Zumo is running 10:14.55 148[dbg] Drive not mounted 10:15.00 149[dbg] Looping before Zumo is running 10:15.00 150[dbg] Drive not mounted 10:15.05 151[dbg] Looping before Zumo is running 10:15.05 152[dbg] Drive not mounted 10:15.10 153[dbg] Looping before Zumo is running 10:15.10 154[dbg] Drive not mounted 10:15.15 155[dbg] Looping before Zumo is running 10:15.15 156[dbg] Drive not mounted 10:15.20 157[dbg] Looping before Zumo is running 10:15.20 158[dbg] Drive not mounted 10:15.25 159[dbg] Looping before Zumo is running 10:15.25 160[dbg] Drive not mounted 10:15.30 161[dbg] Looping before Zumo is running 10:15.30 162[dbg] Drive not mounted 10:15.35 163[dbg] Looping before Zumo is running 10:15.35 164[dbg] Drive not mounted 10:15.40 165[dbg] Looping before Zumo is running 10:15.40 166[dbg] Drive not mounted 10:15.45 167[dbg] Looping before Zumo is running 10:15.45 168[dbg] Drive not mounted 10:15.50 169[dbg] Looping before Zumo is running 10:15.50 170[dbg] Drive not mounted 10:15.55 171[dbg] Looping before Zumo is running 10:15.5Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Fenetre.actionPerformed(Fenetre.java:128) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Fenetre.actionPerformed(Fenetre.java:128) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Fenetre.actionPerformed(Fenetre.java:128)
if(source == jButton3){ JFileChooser choix = new JFileChooser(); choix.setCurrentDirectory(new File("C:/Users/Thomas/Desktop/DVD 3A INFORMATIQUE/200 logiciels")); int option = choix.showOpenDialog(null); choix.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (option == JFileChooser.APPROVE_OPTION) { [code=java]File se = jfc.getSelectedFile(); } }
File se = jfc.getSelectedFile();
if(source == jButton3){ JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(new File("C:/Users/Thomas/Desktop/DVD 3A INFORMATIQUE/200 logiciels")); int option = jfc.showOpenDialog(null); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (option == JFileChooser.APPROVE_OPTION) { File se = jfc.getSelectedFile(); } }
if (option == JFileChooser.APPROVE_OPTION) { File se = jfc.getSelectedFile(); }ne sert à rien et me demande donc si je veux l'effacer, bizarre étant donner que c'est cette ligne qui me permet de choisir les fichiers non ?
import java.io.File; import javax.swing.JFileChooser; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class Test { public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(new File("C:/Program Files (x86)")); jfc.showOpenDialog(null); } }