Results 1 to 3 of 3
  1. #1
    kozaken44 is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default lack of icons representation in the menu bar

    Hi,

    I have a problem with displaying icons in a menubar of my frame. Below is part of the code responsible for it from my frame's constructor:
    Java Code:
    public class MainFrame extends JFrame {
    public MainFrame() {
    super();
    (...)
    JMenuBar menuBar = new JMenuBar();
    (...)
    menu = new JMenu("Help");
    menuBar.add(menu);
    
    menu = new JMenu();
    ImageIcon icon = new ImageIcon("grafiki/dodaj.png");
    menu.add(new JMenuItem(icon));
    menuBar.add(menu);
    }
    }
    after compilation and run what I get is a simple frame with a menu bar containing a string "Help" but no icon next to it. But when I point with a cursor at a point the icon should be, then it displays me a white square of a 20x20 dimension (icon "dodaj.png" has the same dimension).

    What should I do to load the icon into the menu bar and display it there properly?

    Many thanks for help.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,669
    Rep Power
    5

    Default Re: lack of icons representation in the menu bar

    So where you do think Java is going to search for your icon file? You specify a path "grafiki/dodaj.png". Where is that?

    Did you check the javadocs of the class for example?

    ImageIcon (Java Platform SE 7 )
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    kozaken44 is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default Re: lack of icons representation in the menu bar

    I checked it in the Java documentation previously and now. It says:
    An implementation of the Icon interface that paints Icons from Images. Images that are created from a URL, filename or byte array are preloaded using MediaTracker to monitor the loaded state of the image.
    I specified a filename "dodaj.png" which is in the folder "grafiki" in the same project. Is the path not correct?

Similar Threads

  1. Lost Audio Packet Steganography(LACK)
    By dipincem in forum Networking
    Replies: 3
    Last Post: 09-10-2012, 11:07 AM
  2. All Menu Icons
    By java software in forum Java Software
    Replies: 0
    Last Post: 12-13-2011, 05:39 PM
  3. Java Representation
    By lary in forum New To Java
    Replies: 2
    Last Post: 05-08-2011, 07:28 AM
  4. Memory representation of an array?
    By hellolleh in forum Forum Lobby
    Replies: 2
    Last Post: 04-29-2010, 03:05 AM
  5. Lack of memory maintain to Website
    By 82rathi.angara in forum Advanced Java
    Replies: 3
    Last Post: 06-13-2008, 02:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •