java netbeans
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -Dconsole.encoding=UTF-8
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon cannot be cast to class javax.swing.ImageIcon (com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon is in unnamed module of loader 'app'; javax.swing.ImageIcon is in module java.desktop of loader 'bootstrap')
at com.devjs.vista.Principal.lblCarpetaMultimediaMouseEntered(Principal.java:475)
at com.devjs.vista.Principal4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueueJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
a que se debe el error? responde en 5 lineas
Assistant
El error se debe a que estás intentando castear un objeto de tipo FlatOptionPaneErrorIcon (de la librería FlatLaf) a javax.swing.ImageIcon, lo cual no es válido porque FlatOptionPaneErrorIcon no extiende ni es una subclase de ImageIcon. Para solucionarlo, no debes hacer el cast directo; en su lugar, usa el tipo Icon o ajusta el código para utilizar el icono de FlatLaf correctamente sin forzarlo a ImageIcon. Además, revisa la línea 475 en Principal.java donde se produce el cast incorrecto.
User
public Icon obtenerIconoDesdeRuta(String rutaImagen) {
URL urlImagen = getClass().getResource(rutaImagen);
if (urlImagen != null) {
return new ImageIcon(urlImagen);
} else {
return UIManager.getIcon("OptionPane.errorIcon");
}
}
eso lo uso aqui
Porque obtenerIconoDesdeRuta regresa un Icon, pero en caso de que no encuentre la imagen, devuelve un icono de UIManager.getIcon("OptionPane.errorIcon") que no es un ImageIcon sino un FlatOptionPaneErrorIcon. Por eso da el error de cast.
Solución: No hagas cast a ImageIcon directamente, manténlo como Icon y cuando sea instancia de ImageIcon sí escalas la imagen. Algo así:
Icon icon = ctrArchivo.obtenerIconoDesdeRuta("/img/carpetaMultimedia2.png");
if (icon instanceof ImageIcon) {
ImageIcon imagenOriginal = (ImageIcon) icon;
Image imgEscalada = imagenOriginal.getImage().getScaledInstance(
imagenOriginal.getIconWidth() + 10,
imagenOriginal.getIconHeight() + 10,
Image.SCALE_SMOOTH);
lblCarpetaMultimedia.setIcon(new ImageIcon(imgEscalada));
} else {
// Si no es ImageIcon, simplemente usa el icono tal cual
lblCarpetaMultimedia.setIcon(icon);
}
User
lo de instance podria ahcerlo en el metodo? para que deveuvla la iamgen? responde en una linea
Assistant
Sí, puedes modificar el método para que solo devuelva un ImageIcon válido o una imagen por defecto escalada, evitando así el cast fuera del método.
User
obtenerIconoDesdeRuta como harias ese metodo
Assistant
Aquí tienes cómo podrías hacer obtenerIconoDesdeRuta para que siempre devuelva un ImageIcon escalado o uno por defecto si no encuentra la imagen:
public ImageIcon obtenerIconoDesdeRuta(String rutaImagen, int ancho, int alto) {
URL urlImagen = getClass().getResource(rutaImagen);
Image image;
if (urlImagen != null) {
image = new ImageIcon(urlImagen).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
} else {
Icon defaultIcon = UIManager.getIcon("OptionPane.errorIcon");
if (defaultIcon instanceof ImageIcon) {
image = ((ImageIcon) defaultIcon).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
} else {
// Crear un icono vacío o predeterminado en caso de que no sea ImageIcon
image = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_ARGB);
}
}
return new ImageIcon(image);
}
Esto garantiza que el método siempre retorne un ImageIcon con el tamaño solicitado y evita problemas de casteo.
User
usa variables en espñaol, lo uqe quiero es establecer de manera predeterminada esa iamgen si hay un error, no hay imagen predeterminada, solo lo de optionpane, ese emtodo hay dos opciones, o deveuvle la iamgen de la ruta o el optionpane, no hay mas
Assistant
Perfecto, aquí tienes el método ajustado con variables en español, que devuelve un Icon (no necesariamente ImageIcon) y si no encuentra la imagen retorna el icono por defecto de error de OptionPane sin más opciones:
public Icon obtenerIconoDesdeRuta(String rutaImagen) {
URL urlImagen = getClass().getResource(rutaImagen);
if (urlImagen != null) {
return new ImageIcon(urlImagen);
} else {
return UIManager.getIcon("OptionPane.errorIcon");
}
}
Y para evitar el ClassCastException fuera del método, simplemente no hagas cast a ImageIcon, sino trata el Icon como tal y si necesitas escalar, verifica si es instancia de ImageIcon antes de operar:
la logica de instanceof queiro que este en el emtodo, lo voy a suar en varios lugares y no quiero repetir la alogica
este if es necesario? if (defaultIcon instanceof ImageIcon)
public ImageIcon obtenerIconoDesdeRuta(String rutaImagen, int ancho, int alto) {
URL urlImagen = getClass().getResource(rutaImagen);
Image image;
if (urlImagen != null) {
image = new ImageIcon(urlImagen).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
} else {
Icon defaultIcon = UIManager.getIcon("OptionPane.errorIcon");
if (defaultIcon instanceof ImageIcon) {
image = ((ImageIcon) defaultIcon).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
}
}
return image;
}
Assistant
El if (defaultIcon instanceof ImageIcon) es necesario porque UIManager.getIcon("OptionPane.errorIcon") puede devolver un Icon que no sea un ImageIcon (como en tu caso con FlatLaf). Si no haces esta comprobación y haces cast directo, causarás un ClassCastException.
Además, tu método no compila porque return image; espera un ImageIcon, pero image es un Image.
Aquí tienes una versión correcta y limpia con toda la lógica dentro del método, que siempre devuelve un ImageIcon escalado o el icono por defecto sin escalar si no es ImageIcon:
public Icon obtenerIconoDesdeRuta(String rutaImagen, int ancho, int alto) {
URL urlImagen = getClass().getResource(rutaImagen);
if (urlImagen != null) {
Image imagen = new ImageIcon(urlImagen).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
return new ImageIcon(imagen);
} else {
Icon iconoDefecto = UIManager.getIcon("OptionPane.errorIcon");
if (iconoDefecto instanceof ImageIcon) {
Image imagen = ((ImageIcon) iconoDefecto).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
return new ImageIcon(imagen);
} else {
// Si no es ImageIcon, devuelve el icono tal cual sin escalado
return iconoDefecto;
}
}
}
User
veo mucha anidacion, quita lo que no sea necesario, como te dije solo hay dos opciones o devuelve la iamgen de la ruta o el icono predeterminado, no importa que deveuvle, puede ser un iamgeicon o un icon lo que sea, solo que devuelva dos opciones
Assistant
Entiendo, quieres un método simple que devuelva directamente la imagen de la ruta si existe o el icono predeterminado sin preocuparte por escalados ni casteos ni tipos intermedios. Aquí tienes la versión simplificada que cumple eso:
public Icon obtenerIconoDesdeRuta(String rutaImagen) {
URL urlImagen = getClass().getResource(rutaImagen);
if (urlImagen != null) {
return new ImageIcon(urlImagen);
}
return UIManager.getIcon("OptionPane.errorIcon");
}
Así, siempre tienes solo dos posibles valores:
Un ImageIcon con la imagen solicitada
O el icono predeterminado que devuelva UIManager (que puede ser cualquier implementación de Icon)
Luego, quien use este método debe manejar el Icon de forma apropiada (por ejemplo, escalando solo si es un ImageIcon).
User
pero la logica de instanceof debe estar en ese metodo, puede devolver solo dos cosas
Assistant
Perfecto, aquí tienes el método que internamente maneja el instanceof para que siempre retorne un ImageIcon escalado cuando sea posible y, en caso contrario, el icono predeterminado sin escalado, asegurando solo dos opciones devueltas:
public ImageIcon obtenerIconoDesdeRuta(String rutaImagen, int ancho, int alto) {
URL urlImagen = getClass().getResource(rutaImagen);
if (urlImagen != null) {
Image imagen = new ImageIcon(urlImagen).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
return new ImageIcon(imagen);
} else {
Icon iconoDefecto = UIManager.getIcon("OptionPane.errorIcon");
if (iconoDefecto instanceof ImageIcon) {
Image imagen = ((ImageIcon) iconoDefecto).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
return new ImageIcon(imagen);
} else {
// No es ImageIcon, devolvemos un ImageIcon vacío con tamaño solicitado
return new ImageIcon(new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_ARGB));
}
}
}
User
solo puede haber un parametro,
en que caso esto resultaria falso?
Icon iconoDefecto = UIManager.getIcon("OptionPane.errorIcon");
if (iconoDefecto instanceof ImageIcon) {
hay otra forma de devlver una iamgen prederminada? o un simbolo o l ouqe sea predeterminado? por si la ruta falla? cualqueir cosa que proporcione java o netbenas, responde cada duda en una linea
Assistant
iconoDefecto instanceof ImageIcon resultaría falso si el icono predeterminado es una implementación de Icon que no extiende ImageIcon, como un icono vectorial o personalizado (por ejemplo, FlatLaf usa iconos propios no basados en imágenes).
Otra forma de devolver una imagen predeterminada es cargar un recurso propio incluido en tu proyecto (por ejemplo, un archivo PNG dentro de /recursos/img/default.png) y devolverlo como ImageIcon.
También puedes usar caracteres Unicode con JLabel (como un símbolo) o dibujar con Graphics un icono simple para cuando la carga falle, pero no hay un “símbolo predeterminado” universal en Java Swing fuera de los que provee UIManager.
User
para esto es ese metodo, si la ruta falla debe devolver caulquir cosa predeterminada pero no peude ser una iamgen de recursos porque para eso es este error, si falla eso no tiene sentido llamar una iamgen prederminada
si fuera tu tercer opcion que devuvle un icon o imageicon con una x roja, dime cual de los dos enfoques es mejor y mas rapido
Assistant
Para un ícono simple con una "X" roja dibujada al vuelo (sin cargar imágenes externas), lo más rápido y ligero es implementar un Icon personalizado que dibuje la "X" directamente usando Graphics, en lugar de crear un ImageIcon a partir de una imagen.
Esto evita dependencias de archivos, reduce uso de memoria y es muy eficiente para un icono simple.
User
que seria mejor que deveuvle un icon o iamgeicon? responde en una linea
Assistant
Mejor devolver un Icon personalizado, ya que es más flexible y ligero que un ImageIcon cuando dibujas gráficos simples dinámicamente.
User
pero la idea principal de este emtodo es que deveulva un iamgeicon porque trabaja con iamgenes
Assistant
Entonces, para mantener coherencia y que siempre devuelva un ImageIcon (porque tu código lo espera), lo mejor es crear dinámicamente un BufferedImage con la "X" roja dibujada y devolverla envuelta en un ImageIcon.
User
se puede crear la iamgen de la x sin BufferedImage ? con cual seria menos lineas de codigo? responde en una linea
Assistant
No, para crear un ImageIcon con dibujo personalizado necesitas un BufferedImage; usar BufferedImage es la forma más sencilla con menos líneas de código.
User
muestrame como quedaria el emtodo
Assistant
Aquí tienes el método completo que devuelve un ImageIcon con la imagen de la ruta o, si falla, un ImageIcon creado dinámicamente con una "X" roja usando BufferedImage y dibujo directo:
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.URL;
public ImageIcon obtenerIconoDesdeRuta(String rutaImagen, int ancho, int alto) {
URL urlImagen = getClass().getResource(rutaImagen);
if (urlImagen != null) {
Image imagen = new ImageIcon(urlImagen).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
return new ImageIcon(imagen);
} else {
BufferedImage imagenError = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = imagenError.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, ancho, alto);
g.setColor(Color.RED);
g.setStroke(new BasicStroke(3));
g.drawLine(3, 3, ancho - 3, alto - 3);
g.drawLine(ancho - 3, 3, 3, alto - 3);
g.dispose();
return new ImageIcon(imagenError);
}
}
Este método garantiza siempre devolver un ImageIcon válido y visualmente claro cuando la carga falla.
User
sin parametro de ancho y alto, que sea 40 por 40
Assistant
Claro, aquí tienes el método sin parámetros de tamaño, con ancho y alto fijos en 40x40 píxeles:
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.URL;
public ImageIcon obtenerIconoDesdeRuta(String rutaImagen) {
final int ancho = 40;
final int alto = 40;
URL urlImagen = getClass().getResource(rutaImagen);
if (urlImagen != null) {
Image imagen = new ImageIcon(urlImagen).getImage().getScaledInstance(ancho, alto, Image.SCALE_SMOOTH);
return new ImageIcon(imagen);
} else {
BufferedImage imagenError = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = imagenError.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, ancho, alto);
g.setColor(Color.RED);
g.setStroke(new BasicStroke(3));
g.drawLine(3, 3, ancho - 3, alto - 3);
g.drawLine(ancho - 3, 3, 3, alto - 3);
g.dispose();
return new ImageIcon(imagenError);
}
}
User
que solo haya un return y que los nuemros bayan directo en el emtodo
Assistant
Aquí tienes el método con un solo return y los valores numéricos usados directamente dentro del código:
eso consume menos que optionopane imagen, responde en una linea
Assistant
Sí, crear y dibujar un BufferedImage simple consume generalmente menos recursos que cargar y renderizar el icono complejo que usa UIManager.getIcon("OptionPane.errorIcon").
User
imagina que el metodo devuelve un icon
Icon imagenOriginal = ctrArchivo.obtenerIconoDesdeRuta("/img/carpetaMultimedia2.png");
como aria lo siguiente?
Image img = imagenOriginal.getImage().getScaledInstance(
imagenOriginal.getIconWidth() + 10,
imagenOriginal.getIconHeight() + 10,
Image.SCALE_SMOOTH);
porque Image no puede usar getImage
solo responde con la linea qeu auemnta +10
podria ser
imagenOriginal = a ((ImageIcon) imagenOriginal).getImage().getScaledInstance(imagenOriginal.getIconWidth() + 10, imagenOriginal.getIconHeight() + 10, Image.SCALE_SMOOTH);
responde en una linea
Assistant
No, no puedes asignar un Image directamente a un Icon; debes crear un nuevo ImageIcon así:
g.fillRect(0, 0, 40, 40); que hace eso? responde en una linea
Assistant
g.fillRect(0, 0, 40, 40); pinta un rectángulo sólido de 40x40 píxeles empezando en la coordenada (0,0) del área de dibujo.
User
BufferedImage imagenError = new BufferedImage(40, 40, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = imagenError.createGraphics();
g.setColor(Color.BLUE);
g.fillRect(0, 0, 40, 40);
g.setColor(Color.RED);
g.setStroke(new BasicStroke(3));
g.drawLine(3, 3, 37, 37);
g.drawLine(37, 3, 3, 37);
g.dispose();
resultado = new ImageIcon(imagenError);
si quisiera que sea 10x10 como seria? solo responde con este fragmento
ControladorArchivo ctrArchivo = new ControladorArchivo();
ImageIcon imagenOriginal = ctrArchivo.obtenerIconoDesdeRuta("/img/carpetaMultimedia2.png");
Image img = imagenOriginal.getImage().getScaledInstance(imagenOriginal.getIconWidth() + 10, imagenOriginal.getIconHeight() + 10, Image.SCALE_SMOOTH);
lblCarpetaMultimedia.setIcon(new ImageIcon(img));
siguiendo las buenas p´racticas esta bien o hay redundacia? responde en una linea
Assistant
Hay redundancia al almacenar primero en imagenOriginal si solo vas a escalar y usar la imagen; puedes simplificar escalando directamente sin guardar el ImageIcon original si no lo necesitas luego.
User
siguiendo las buenaspracticas como seria?
Assistant
Siguiendo buenas prácticas, asigna directamente el icono escalado sin crear variables intermedias innecesarias así:
Así evitas variables intermedias innecesarias y mejoras legibilidad.
User
el segundo enfoque es igual al mio, analzia bien y dime cual es el mejor, responde en una linea
Assistant
Tu enfoque es correcto y claro; para mayor limpieza evita crear variables intermedias innecesarias solo si no reutilizas el icono original, pero funcionalmente son equivalentes y ambos siguen buenas prácticas.
User
imagenOriginal solo lo utilizo en ese metodo
Assistant
Entonces lo más limpio y eficiente es no usar variable intermedia y asignar directamente así:
Aunque para evitar llamar tres veces al método, es mejor guardar el resultado en una variable temporal.
User
pero al tener mucho codigo apilado no es buena pratica? responde siguiedno la sbuenas practicas
Assistant
No, no es buena práctica llamar repetidamente al mismo método ni apilar demasiado código en una sola línea; lo correcto es almacenar el resultado en una variable para mejorar legibilidad y eficiencia, así:
BufferedImage imagenCapturada
imagenCapturada.getScaledInstance(dimension.width, dimension.height, Image.SCALE_SMOOTH);
como puedo lamcenar eso en un iamgeicon? respond en una linea
Assistant
ImageIcon iconoEscalado = new ImageIcon(imagenCapturada.getScaledInstance(dimension.width, dimension.height, Image.SCALE_SMOOTH));
User
public ImageIcon obtenerImagenEscalada(BufferedImage imagenCapturada) {
ImageIcon imagenGif = obtenerIconoDesdeRuta("/img/loading.gif");
que pasa si imagenCapturada es nula? y si la ruta esta mal? responde en una linea
Assistant
Si imagenCapturada es nula, se devolverá el icono del GIF de carga; si la ruta está mal, obtenerIconoDesdeRuta devolverá el icono predeterminado de error definido en ese método.
User
BufferedImage imagenError = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = imagenError.createGraphics();
g.setColor(Color.BLUE);
g.fillRect(0, 0, 10, 10);
g.setColor(Color.RED);
g.setStroke(new BasicStroke(1));
g.drawLine(1, 1, 9, 9);
g.drawLine(9, 1, 1, 9);
g.dispose();
resultado = new ImageIcon(imagenError); que tenga 20 de tamaño
Así evitas el cast incorrecto y proteges el código cuando el icono es otro tipo distinto a ImageIcon.
Así mantienes la lógica clara y evitas errores de casteo.
Resumen: El instanceof es necesario para evitar el ClassCastException. Si el icono por defecto no es ImageIcon, simplemente devuélvelo sin escalar.
Explicación:
Si existe la imagen, devuelve la imagen escalada en un ImageIcon.
Si no, intenta devolver el icono de error predeterminado escalado si es ImageIcon.
Si el icono predeterminado no es tipo ImageIcon, devuelve un icono vacío escalado para mantener siempre un ImageIcon y evitar errores o casteos fuera del método.
Así, garantizas que el método solo retorne un ImageIcon válido en cualquier situación, simplificando el manejo en el resto del código.