Trying to add an icon to a JPanel!

After declaring the icon w/ :
ImageIcon icon = new ImageIcon("logo2.gif");
and the JPanel is added to the content pane, the error I am recieving is w/ this peice of code: jPanel1.add(icon);
The error is: cannot reslove symbol, jPanel1.add(icon);
^
I'm nit sure what the deal is...

Here is some working code.You just have to center and resize the image.
JFrame frame = new JFrame();
    frame.setSize(800,600);
    JLabel jLabel1 = new javax.swing.JLabel();
    JPanel jPanel1 = new javax.swing.JPanel();
    frame.getContentPane().setLayout(new javax.swing.BoxLayout(frame.getContentPane(), javax.swing.BoxLayout.X_AXIS));
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(java.awt.event.WindowEvent evt) {
    jLabel1.setText("DMV Icon");
    ImageIcon icon = new ImageIcon("logo2.gif");
    frame.getContentPane().add(jLabel1);
    jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
    jPanel1.setMaximumSize(new java.awt.Dimension(120, 90));
    jPanel1.setMinimumSize(new java.awt.Dimension(120, 90));
    jPanel1.setPreferredSize(new java.awt.Dimension(120, 90));
    JLabel l = new JLabel();
    l.setIcon(icon);
    jPanel1.add(l);
    jPanel1.setBackground(Color.red);
    frame.getContentPane().add(jPanel1);
    frame.show();Hope this helps.

Similar Messages

  • I trying to add print Icon in Thread Pane or Message Pane can you help?

    I trying to add print Icon in Thread Pane or Message Pane can you help?

    You have shown us Firefox.
    How does that relate to doing it in Thunderbird?

  • Trying to add PDF icons to my Assignment Block (CRM 7 WebUI)

    Hello gurus,
    I am trying to display a pdf icon in every row of my assignment block in CRM 7 WebUI. I am using one click actions, so I have an actions column, and I the logic to make the icon image appear is in the GET_OCA_T_TABLE of the context node class. When I create actions like delete and edit, it is very easy to get the icons, for example, the following code works perfectly and the icons are displayed in the assignment block:
       ls_one_click_action-id      = 'DELETE'.
        ls_one_click_action-icon    = 'delete.gif'.
        ls_one_click_action-text    = ''.
    ls_one_click_action-id      = 'EDIT'.
        ls_one_click_action-icon    = 'edit.gif'.
        ls_one_click_action-text    = ''.
    But, I cannot add a pdf icon.... I have tried the paths to PDF icons in the MIME repository, and I have tried getting the PDF icons like this cl_thtmlb_util=>GC_ICON_FILE_PDF or with cl_thtmlb_util=>get_icon_url(pdf)... nothing displays anything but a broken image.
    Please help me!  <text removed>
    Jonathan
    Edited by: Matt on Jun 27, 2011 10:18 AM

    Thanks!!!
    You mean, in the .htm file?? Well that would not work, at least not in my case, because there is almost nothing in the .htm.. Anyways, thanks a lot. I did not find it your way.... In the debugger, I found the path through the MIME repository to the default MIME types for THMLB.
    Now I have to open a PDF file in IXOS in a new window in the WEBUI....... how can I call a PDF in IXOS based on my an object ID??
    Thank you!!
    Jonathan

  • Trying to add Applications icon to Dock

    I reinstalled my Mac OS, Maverick. How do I add the Applications folder to the Dock? When I try, it looks as if all my apps are being copied to the newly created Dock icon for Applications, because of the blue progress bar under the icon. And it seems to be stuck as it has not moved in quite awhile.

    Hello there, Chris.
    The following Knowledge Base article explains how to add a folder to the Dock:
    Mac Basics: The Dock
    http://support.apple.com/kb/ht2474
    Adding and removing Dock items
    If you want to add an application to the Dock, click the Launchpad icon in the Dock and drag the application icon to the Dock; the icons in the Dock will move aside to make room for the new one. If you want to add a file or folder to the Dock, just drag its icon from any Finder window (or the desktop) and drop it on the Dock. The resulting icon that appears in the Dock is actually an alias of the original item (it's kind of a pointer to your original item). If you drag an application or file onto the Dock, you'll be able to open it anytime by simply clicking its docked icon. If you drag a folder onto the Dock, a Finder window of the folder's contents will display when you click the folder icon in the Dock.
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • HT2495 I have a wirless network. I connect all my computers to it and a printer. I can print wirelessly from all computers. I tried to add the printer to my new Macbook, but can't find the printer on the add printer and scan icon on preferences.

    I have a wirless network. I connect all my computers to it and a printer. I can print wirelessly from all computers. I tried to add the printer to my new Macbook, which is connecte to the network, but can't find the printer on the add printer and scan icon on preferences. I downloaded a installation printer utility from the Manufacturer (lexmark), but it didn't work. Any sugestions?
    Thanks,
    Ivette

    You would need to get the IP address of your printer then manually add a network print queue.
    To get the IP address, on the control panel of your printer, press on Setup > Network Setup > TCP/IP > View/Set IP address.

  • Add Image icon to jpanel

    I have to add an image to a jpanel.
    I am using the below code
    I have already defined the jlabel(lblImageIcon) using the netbeans design palette and made the jlabel visibility false.
    lblImageicon=new JLabel
    lblImageicon.setText("ImageIcon")
    gridBagConstraints =new java.awt.GridBagConstraints
    gridBagConstraints .gridX=2
    gridBagConstraints .gridY=2
    add(lblImageIcon,gridBagConstraints )
    Then when I have to show the image upon a condition I have the following
    ImageIcon icon = new ImageIcon("http://ipaddress/test/test.png)
    lblImageIcon.setIcon(icon)
    lblImageicon.setVisible(true)
    The iamge does not show up.If I do a system.out afetr the line
    ImageIcon icon = new ImageIcon("http://ipaddress/test/test.png)
    It show as http://ipaddress/test/test.png)
    I am not sure whether it is reading the image or not showing the image because of size.Also my application uses applet and I am signing the applet.
    Is there any other way to add the images or what am I doing wrong or missing.
    Thanks,

    The code is without code tags (read the 2nd post of the forum), the link is broken, and an SSCCE would still be the best.

  • How to add an image in a JPanel

    Hi All,
    How to add an image in a JPanel and make it display.
    Thanks,

    I have tried with the below code. If I there is any fault please correct me.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class HomePage extends JFrame implements     ActionListener {
        JButton cmdClick;
        JLabel label;
        JPanel homePanel = new JPanel();
        JPanel headPanel = new JPanel();
        JPanel btPanel = new JPanel();
        private JPanel mainPanel = new JPanel(new CardLayout());
        CardLayout cl;
        CalScenario calcFrame = null;
        public HomePage() {
           setTitle("Test Kit");
           setSize( 1008,399);
           setBackground( Color.gray );
           setResizable(false);
           Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
           Rectangle window = getBounds();
           setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
           setVisible(true);
            homePanel.setLayout(new BorderLayout());
            headPanel.setPreferredSize(new Dimension(1008,153));
            label = new JLabel("Main menu");
            headPanel.add(label);
            headPanel.setBackground(Color.CYAN);
            ImageIcon icon = new ImageIcon("images/slash.gif");
            JLabel imglabel = new JLabel();
            imglabel.setIcon(icon);
            headPanel.add(label);
            this.getContentPane().add(headPanel);
            btPanel.setBackground(Color.ORANGE);
            cmdClick = new JButton("Click here");
            btPanel.add(cmdClick);
            cmdClick.addActionListener(this);
            homePanel.add("North",headPanel);
            homePanel.add("West",btPanel);
            calcFrame = new CalScenario(mainPanel);
            mainPanel.add(homePanel, "HomePanel");
            mainPanel.add(calcFrame, "CalcFrame");
            cl = (CardLayout) (mainPanel.getLayout());
            add(mainPanel);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void actionPerformed(ActionEvent source)  {
          if (source.getSource() == (JButton) cmdClick) {
                cl.show(mainPanel, "CalcFrame");
        public static void main( String args[]) {
             HomePage homeFrame = new HomePage();
             homeFrame.setVisible(true);
    }

  • What code can i use to add an image to a JPanel?

    I tried multiple image tutorials and none of those supplied me with a way to add an image to a JPanel without using hidious code. Don't anyone know simpler code which i can use?

    Don't anyone know simpler code which i can use?Simpler than what? Post what you've got at the moment. Use code
    tags as described here: http://forum.java.sun.com/help.jspa?sec=formatting
    About the simplest I can think of is to make a JLabel using the
    constructor that takes an Icon argument, and then add it to the JPanel.
    (The Swing forum is the best place for this.)

  • Can't open another window in firefox and add-on icons won't show

    I had to do a system restore after downloading malware which avast stopped from activating. I downloaded Spybot and scanned/fixed various things it had identified but then my laptop wouldn't start in anything but safe mode. After I did the system restore, the malware and Spybot were gone, but Firefox crashed every time I tried to open it, so I had to use Internet Explorer to get online and download Firefox. Since then I have 2 problems: Firefox will only open in one window (it will let me open multiple tabs but only in one window) and my add-on icons (the Personas fox, the Greasemonkey monkey, the Boost for facebook infinity symbol, etc) won't appear on the bottom toolbar or browser bar as they always have, nor are they in the Tools drop-down menu as they always were. I can't get into Personas favorites at all either, despite having reinstalled the Personas Plus account twice. I assume that something causing these things happened when I did the system restore, as anything Spybot "fixed" should have been undone by the system restore? I have Vista 32-bit on a Dell Inspiron 1545 laptop. Please help!

    Hi narik121,
    So the build that you downloaded for CentOS 6.4, where did you download it from?
    There are some versions of Firefox that may have been compiled by third party providers for specific Linux builds. Mozilla does not host these builds. [[Install Firefox on Linux]] is the reference to the official code for Linux.

  • Acrobat xi - RE: Add sound icon- skin displayed is a 'blank white box' until it is clicked to activate it- can you lock skin to display before its activated so that in a print run the skin shows up (ie the controls-or any kind of greyed out rectangle, lik

    Hi,
    Acrobat xi - RE: Add sound icon- skin displayed is a 'blank white box' until it is clicked to activate it- can you lock skin to display before its activated so that in a print run the skin shows up (ie the controls-or any kind of greyed out rectangle, like video controls before 1st activation) and not the blank white box- if no, I guess I have to activate all sound icons before doing a print run?thanks)).

    Many of your points are totally legitimate.
    This one, however, is not:
    …To put it another way, the design of the site seems to be geared much more towards its regular users than those the site is supposedly trying to "help"…
    The design and management of the forums for more than five years have driven literally dozens of the most valuable contributors and "regulars" away from the forums—permanently.
    The only conclusion a prudent, reasonable person can draw from this state of affairs is that Adobe consciously and deliberately want to kill these forums by attrition—without a the PR hit they would otherwise take if they suddenly just shut them down.

  • I am trying to add a bookmark in safari ios7, but when I tap the box/arrow up button nothing happens and no options appear on screen to be able to add a bookmark.  In fact the screen freezes, can smeone please help?

    I am trying to add a bookmark in safari ios7, but when I tap the box with the upward arrow no options appear anywhere on screen to add a bookmark.  In fact the screen freezes and I have to close safari to be able to unfreeze it.  What is wrong, can anyone please help me?  Thanks

    please ignore this question, I added the ios7.0.2 patch and the bookmarks can now be added through the action icon.  cheers

  • Trying to add a simple applet to a web page

    Well, I was trying to add a simple applet to a web page(php nuke Home section), it didn't fin my applet, so I changed it and added it to a simple html file to make it as simple as I could get it.
    This is the code in the html file:
    <applet code="usblock.class" width="400" height="400">The browser doesn't support applets...</applet>The directory: www/usblock.html & www/usblock.java & www/usblock.class - As you can see the files are all in the same directory/folder.
    usblock.java code:
    import javax.swing.*;
    import java.awt.*;
    public class usblock extends JApplet
         public void init()
              JPanel p = new JPanel(new BorderLayout());
              p.add(new JLabel("Heisann"));
              add(p, BorderLayout.CENTER);
    }now as I open the html local on my computer, it workes. As soon as I open the usblock.html from my website, it doesn't.
    It gives me this error here:
    load: class usblock.class not found.
    java.lang.ClassNotFoundException: usblock.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 moreSo I thought it was that it couldn't find the .class file. Well, I went through the How To add applets that I found somewhere on sun.com. It had exactly the same as I had.
    Im figuring the problem is something easy and not hard to detect. But my eyes can't find it somehow. This is my second time trying applets, and I kinda forgot how I got it to work the first time.
    Im just glad for all the help I can get.
    Thanks a lot.
    LordSvae
    PS: Sry for the size of the post, but I'm not sure how much info I was supposed to put in here, so I thought the more the better, right? :S

    Hii,
    I doesn't know the solution but same kind of problem is come with me & I found that the problem is of Path i.e. you need to set a codebase attribute . For tempory solution what i do i simply copy the .class file in to html file dir.

  • Which Listener I should use if I drag and Drop an image/icon into a JPanel?

    Dar Friends:
    Happy new year.
    I try to drag and Drop an image/icon into a JPanel, and hope I can immediately detect it after DND,
    Which Listener I should use in this JPanel if I drag and Drop an image/icon into a JPanel??
    Thanks

    Thank camickr .
    I can dnd an image into a JPanel called JPanelOld already, I hope to use another JPanel or JTree to listen to any Dropped Image in JPanelOld later on so I can take some action in another JPanel or JTree.
    so what kind of Listener I should use for my purpose??
    where to add this Listeners??
    Happy New Year.

  • Can't find print window to set my printer when I click on the printer add on icon

    My Epson printer is set as default printer. I am unable to find the print window to add my printer to firefox when trying to print from the add on icon.

    '''{ Ctrl + P }''' then select that printer from the Print - Name dialog drop-down. Then print the page.
    "last used" is the default for Firefox - doesn't go by the system default. setting in the operating system

  • Content Cannot Be Displayed in a Frame When Trying to Add Item

    We have a user that is trying to add an item to a SharePoint Calendar.  She using using IE9 browser in IE9 compatibility mode.  When she selects a date then clicks on "add item", the dialog box pops up, but it displays "The Content
    cannot be displayed in a frame".  When I try adding and item it works fine for me. 
    I'm at a loss on this one.  Has anyone experienced this or know what is going on?
    Thanks

    To resolve this issue, follow these steps:
    Click Start, click Control
    Panel, and then click Internet Options.
    Note Make sure that you view Control Panel by
    using either small icons or large icons.
    Click the Security tab, click Trusted
    sites, and then click Sites.
    Enter your SharePoint Url, click Add,
    then click Close.
    Make sure that the Enable Protected Mode check
    box isn't selected.
    Close all web browsers, and then try again with a new session.
    Ibrahim Sukari, Technical Consultant | SharePoint | Dynamics CRM |
    LinkedIn Profile

Maybe you are looking for

  • How do I find a previous windows version. It's telling me to copy files and then delete old version.

    When I got on my laptop today, I saw that there was a message from HP Support Assistant. It says that I have an older versions of windows and that the previous versions of windows was saved in a folder c:\windows.old. it says that the folder is very

  • Dynamic edit on a Report.

    Hi, I have a report where I am giving edit link for each record. By clicking this user can go to another page where they can edit this record. But, the requirement is that this button should apprear only for those records where its status is of certa

  • a:commandButton not working properly.

    Hi, I am currently into making a seam application with ajax,jsf etc in order to make myself familiar with those technologies. The problem is that i am trying to create a button. When this button is clicked, a method should be execute, which in turn e

  • Authorisation for creator to confirm his messages in support desk

    Hi Friends, I have configured support desk functionality where user creates a support message.This message is handled by 1st level support team.If  1st level  is not able to resolve it is sent to 2nd level. Also support message can be created by 1st

  • Using "in clause" for more than one collumn

    Hallo, for the following statement, I got the error "FEHLER in Zeile 16: ORA-00920: Ungultiger relationaler Operator". What is wrong on it? SELECT 'ALTER TABLE ' || c.owner || '.' || c.table_name || ' MODIFY(' || '"' || c.column_name || '"' || c.data