• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JApplet + JPanel + image.jpg

 
Marcin Dabrowski
Greenhorn
Posts: 5
Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm currently making this simple gui tool and I want to use JApplet class. My plan is to use JApplet instead of JFrame class. Currently I've JPanel with image attached to it and I want to add this little thing to JApplet. Unfortunately I don't see image in JPanel. Something is definitely wrong. Image.jpg is in JPanel in case when I'm using JFrame but It's not working with JApplet. Does anybody know how to do this correctly?

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcin Dabrowski wrote:Hi,

I'm currently making this simple gui tool and I want to use JApplet class. My plan is to use JApplet instead of JFrame class. Currently I've JPanel with image attached to it and I want to add this little thing to JApplet. Unfortunately I don't see image in JPanel. Something is definitely wrong. Image.jpg is in JPanel in case when I'm using JFrame but It's not working with JApplet. Does anybody know how to do this correctly?



Are you adding your JPanel to the JApplet's contentPane? It's hard to know what you're doing wrong without code. My main suggestion for you is to create and post an SSCCE showing your problem. Please check out the SSCCE link to see how to make this application in such a way that we can help you more easily.

Best of luck!
 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. Post your code. For all we know it might be that basic beginner error where you think a FIle object can be used to access a resource on the server where the applet was downloaded from.
 
Marcin Dabrowski
Greenhorn
Posts: 5
Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys,

Ok, perhaps you're right. Maybe I just making elementary mistakes in here. Who knows? Currently I'm doing something like this. Resource path to image is correct (I've checked it) and this image should be displayed in panel. One thing is funny. When I do the same with JFrame and just add the new Panel() everything works perfect.
 
pete stein
Bartender
Posts: 1561
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcin Dabrowski wrote:Ok, perhaps you're right. Maybe I just making elementary mistakes in here. Who knows?


Perhaps. You appear to be obtaining your image via the Toolkit's createImage(String filename) method, and I believe that this won't work with applets since for applets files don't exist (corrections most welcome here!). I'm no applet expert, but I've seen code work where the image is obtained using the ImageIO read(InputStream input) method that takes an InputStream for parameter and pass in the image as a resource via class's getResourceAsStream(String name) method. Note that the name passed into this last method is the resource relative to the class file location and so will usually not be the same String that you pass into the createImage method that you use.
 
Marcin Dabrowski
Greenhorn
Posts: 5
Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you show me this on my example?
 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 47.
 
Marcin Dabrowski
Greenhorn
Posts: 5
Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Was what I needed. Thank you ;)
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcin Dabrowski wrote:Was what I needed. Thank you ;)


You're quite welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic