| | |
Image Icon displays file name text
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 28
Reputation:
Solved Threads: 0
Hi, I've followed the example in my lecture notes and it doesn't work! I want to add an image to a label and then add that label to my sub north panel. I want to do this with creating a new class...I'm not sure if I need an "image loader" or to repaint it from the paint method...This code seemed to work for my lecturer:
The label and logo is initialised at the beginning of my application with the Jlabel and ImageIcon var type, I have imported it, tried it without the file path with solely the file name and have tried different file types. I did look at previous posts about this but the code seemed a bit lengthly considering that I simply want to add an image.
Anyone got any ideas on how I could do this easily?
Java Syntax (Toggle Plain Text)
logo = new ImageIcon("JavaProgram2/LogoGIF.GIF"); logoLabel = new JLabel(" " + logo); logoLabel.setOpaque(true); logoLabel.setBackground(Color.white); row2.add(logoLabel); //row2 is the name of the panel
The label and logo is initialised at the beginning of my application with the Jlabel and ImageIcon var type, I have imported it, tried it without the file path with solely the file name and have tried different file types. I did look at previous posts about this but the code seemed a bit lengthly considering that I simply want to add an image.
Anyone got any ideas on how I could do this easily?
The only thing I can think of looking at this code is: do you have an image file called LogoGIF.GIF in a subdirectory called JavaProgram2? Also, you have added the logoLabel to the panel, but you haven't provided the code where you add the logo to the panel or the panel to the rest of your GUI. Are you doing that?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
Join Date: Nov 2007
Posts: 28
Reputation:
Solved Threads: 0
lol yes I have the right name, I've looked at for a long time and row2 is a panel:
row1 = new JPanel();
row2 = new JPanel();
pNorth.add(row1, BorderLayout.NORTH);
pNorth.add(row2, BorderLayout.SOUTH);
row1.setBackground(Color.white);
row2.setBackground(Color.white);
I don't know, I've tried to resize it to a smaller size now and still doesn't work. I run out of ideas
I know the panel works because it's added other buttons...
row1 = new JPanel();
row2 = new JPanel();
pNorth.add(row1, BorderLayout.NORTH);
pNorth.add(row2, BorderLayout.SOUTH);
row1.setBackground(Color.white);
row2.setBackground(Color.white);
I don't know, I've tried to resize it to a smaller size now and still doesn't work. I run out of ideas
I know the panel works because it's added other buttons... ![]() |
Similar Threads
- SpeedUp Your Window XP Never Than Before (Windows tips 'n' tweaks)
- Creating a "Data" folder in my C: Drive using my Java program (Java)
- Open In New Window Php (PHP)
- Error Creating Folder message during installation (OS X)
Other Threads in the Java Forum
- Previous Thread: drawing question
- Next Thread: Show an oval moving up til a value in an array?
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows





