Ho visto che nella tua firma usi JBuilder 7 ... non ti ha mai dato problemi di questo tipo ?
Ho visto che nella tua firma usi JBuilder 7 ... non ti ha mai dato problemi di questo tipo ?
SO : Windows XP - Linux Gentoo
Java - Visual Basic - C++
Ho utilizzato il metodo setIcon .... ora funziona!
Grazie ancora Zero-2
SO : Windows XP - Linux Gentoo
Java - Visual Basic - C++
Non restituisce null perche' probabilmente l'oggetto viene creato comunque, io credo che il problema sia il percorso.
Ti consiglio, in generale, di controllare il percorso dell'immagine, prima di caricarla, per assicurarti che esso esista.
Piccolo esempio:
Eventualmente potresti gestire gli errori nel blocco catch e creare un pulsante senza icona.codice:String path = System.getProperty("user.dir"); path += File.separator + "immagini" + File.separator + "smile.gif"; try { File icon = new File(path); if(icon.exists()) GUI.Ingresso.class.getResource("smile.gif") else System.err.println("Impossibile caricare " + path); } catch(Exception e) {}
Ciao,
Lorenzo
Se non trova l'immagine o il percorso restituisce null
getResource
public URL getResource(String name)Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the * defining class loader of the class.
This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResource.
Parameters:
name - name of the desired resource
Returns:
a java.net.URL object.
Since:
JDK1.1
See Also:
ClassLoader
Lang=Java
Ambiente = Eclipse forever
Ubuntu& Win XP Pro
Hai ragione, devo essermi sbagliato con le immagini. Ho avuto un problema simile in un programma che sto facendo, e ho risolto in quel modo.![]()
Ciao,
Lorenzo