Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Icons not visable?

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Exclamation Icons not visable?

    I'm making it so that users can switch the theme of the icons for the JOptionPane (java defult, windows defult, and a custom one). the method works fine inside the class its declared in but when calling it outside of the class I'm getting this error:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at GUI.setImageIcon(GUI.java:286)
            at Updater.checkForUpdates(Updater.java:28)
            at GUI.actionPerformed(GUI.java:172)
            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 Sour
    ce)
            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 Sour
    ce)
            at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
    ce)
            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 Sour
    ce)
            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)

    The method setImageIcon if defined in the class GUI. here it is:

    public ImageIcon setImageIcon(String iconSet) {
    		ImageIcon iconType = null;
    		if (iconStyle.equals("Emotocons")) {
    			if (iconSet.equals("inform")) {
    				iconType = happyface;
    			}
    			if (iconSet.equals("error")) {
    				iconType = angryface;
    			}
    			if (iconSet.equals("warning")) {
    				iconType = anotherface;
    			}
    		}
     
    		if (iconStyle.equals("java_defult")) {
    			if (iconSet.equals("inform")) {
    				iconType = javaInfo;
    			}
    			if (iconSet.equals("error")) {
    				iconType = javaError;
    			}
    			if (iconSet.equals("warning")) {
    				iconType = javaWarning;
    			}
    		}
     
    		if (iconStyle.equals("windows_defult")) {
    			if (iconSet.equals("inform")) {
    				iconType = windowsInfo;
    			}
    			if (iconSet.equals("error")) {
    				iconType = windowsError;
    			}
    			if (iconSet.equals("warning")) {
    				iconType = windowsWarning;
    			}
    		}
     
    		return iconType;
    	}

    Now when I call that outside of the class GUI is when i get there error. I'm calling it in the class Updater. here it is:

    if (command.equalsIgnoreCase("update")) {
    			JOptionPane.showMessageDialog(null, "There is a more recent version. " +
    					"\nPlease download it on the website!", "Free RS Membership Updater", JOptionPane.WARNING_MESSAGE, g.setImageIcon("warning"));
    		} else {
    			JOptionPane.showMessageDialog(null, "You have the most recent version!", 
    					"Free RS Membership Updater", JOptionPane.INFORMATION_MESSAGE, g.setImageIcon("inform"));
    		}

    I did try this before and it said I didnt have the icons set visible but I rewrote the method since then and now I cant seem to get it to work.. please help!
    Last edited by frozen java; November 12th, 2011 at 02:44 AM. Reason: fixed


  2. #2
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Icons not visable?

    i fixed it

Similar Threads

  1. Using Icons in JOptionPane
    By Jchang504 in forum AWT / Java Swing
    Replies: 3
    Last Post: September 19th, 2014, 02:28 PM
  2. JTree Selection Order Icons
    By pradeeprkm in forum AWT / Java Swing
    Replies: 1
    Last Post: August 1st, 2011, 07:58 AM
  3. Setting Icons and checking for matches
    By Norflok669 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 22nd, 2010, 08:52 PM