Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 15 su 15

Discussione: [Java] Immagini

  1. #11
    Utente di HTML.it L'avatar di Fra
    Registrato dal
    Oct 1999
    Messaggi
    221

    x Zero-2

    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++

  2. #12
    Utente di HTML.it L'avatar di Fra
    Registrato dal
    Oct 1999
    Messaggi
    221

    Ora funge!

    Ho utilizzato il metodo setIcon .... ora funziona!
    Grazie ancora Zero-2
    SO : Windows XP - Linux Gentoo
    Java - Visual Basic - C++

  3. #13
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    315
    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:
    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) {}
    Eventualmente potresti gestire gli errori nel blocco catch e creare un pulsante senza icona.
    Ciao,
    Lorenzo

  4. #14
    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

  5. #15
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    315
    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

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.