473,287 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Display Image using ImageIcon and JLabel

Im trying to display a png image by setting it as a ImageIcon and then putting that in a JLabel. I cant get it to display the image. I am using a null layout as it is the simplest way for me to get everything displayed how I want it to be. Here are the snippets of my code that I think are the important parts. Let me know if there is anything else needed to help me. Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. JLabel dice1 = new JLabel();
  2. ImageIcon one = new ImageIcon("dice/1.png");
  3.  
  4. //set dice1 position
  5. dice1.setLocation(20, 100);
  6. dice1.setSize(115, 115);
  7. dice1.setIcon(one);
  8. gamepanel.add(dice1);
  9.  
Nov 27 '08 #1
2 15949
Dököll
2,364 Expert 2GB
Looks like it should work, what errors are you gettting?
Dec 1 '08 #2
I wasn't getting any errors. I figured out that the problem was the path to the image. I was using the path from the java file but that wasn't where the path should have been from. Thanks for replying tho!
Dec 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: prabhat | last post by:
Hi, I am getting this weird behavior. I have couple of gif and jpg files that I would like to display in JLabel. It displays one jpg image but it does not display other gifs and jpgs. Any idea why...
1
by: AIK | last post by:
Can someone show me or point me to a nice tutorial on showing imageicon images in a jframe? Thanks.
0
by: Mik | last post by:
I have a problem with drawing ImageIcon objects on a JPanel in a JApplet Everything is ok when I run applet locally, but when it's run from a server the images are not showing ImageIcon objects...
1
by: Apirsun | last post by:
I've been trying to use loops to add labels to a frame. I was able to get the program to compile but the labels aren't showing up. import javax.swing.*; import java.awt.*; import...
20
by: fatfatpopo | last post by:
Anyone who understand the codes below, can you please kindly explain to me by adding comments.. thanks in advance // <applet code="ImageSlider" width="400" height="400"></applet> import...
6
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
1
by: javatech007 | last post by:
Here is my code for displaying an image but doesnt work. It runs but displays nothing! import javax.swing.*; import java.awt.*; public class Frame extends JFrame { private JLabel...
2
by: chanshaw | last post by:
Alright I'm trying to place the textarea on top of the image but right now it displays the textarea below the image, how do i go about doing this. import java.awt.Color; import...
5
by: Scaran54 | last post by:
Hello, I am following a tutorial but have a problem. With the following code the icons will not appear unless I specify the entire path to where they are located, I cant work out why it wont work,...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.