• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Graphics

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty much a Java "newbie", and need some help with my GUI. I have a graphic ('logo.bmp' at 66x70pixels) and I want to use it as my logo for the GUI, how do I go about this?

Please keep in mind I'm not using HTML to access the *.java file, I'm using JCreator.


Thanks in advance,
Adam.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Easiest way is just to create a JLabel and give it the name of your image file.

 
Adam Seesfour
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, but, again I'm a total newbie.

After I instantiate the actual picture, then all thats left to do it place it on screen, but, how do I do that?
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a suggestion. Using the JLabel as Gregg recommended is the easy way. You can use methods in the JLabel api such as setBorder and setPreferredSize to dress it up. The second possibility is for more specialized (advanced) work and with this you can draw graphics on/with the image.

The ImageIo class is new with the J2SE 1.4 release so if you are using an older version of java it won't work. In that case we can use the MediaTracker class to load the image.
 
Adam Seesfour
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I'm using 1.3, and part of the assessment things is that I used 1.3, so upgrading is out of the question.

JLabel, if this is the easiest option, and the least stressfull and time-comsuming, then I want to use this option, I don't need to draw on the logo, I just need it displayed on screen.

I know I'm asking alot, but would someone mind showing me code that they've written (or write some out for me, which would be really helpful..with comments of course to direct me and help me out).

I just need a picture on the screen...help me.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adam,

We are more than happy to help. But no one is going to just give you the code. Especially since this smells of homework. What have you tried? Have you even writtten a line of code yet? That's the first step.

The next step would be to go through the JLabel Tutorial. That should be enough to get you going. When you have attempted this yourself, if you are still having problems, show us the code and tell us what problems you are having.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To make things easier, you'll want to convert your bmp to a gif, jpg, or png since it's much easier to work with those in Java.

To see some example code, check out my freeware splash screen:
http://filenabber.com/free-java-classes
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I hate to interrupt this thread with a modifying question, but out of curiosity, coming from VB, I'm used to binding an image to a picture/image control then adding it to a form (jframe/window) - so, binding an image to a label control i.e. class, seems quite odd. Is there a way to setup an image and add it to a panel directly? - I tried and there is no contructor for an image/imageicon class. It's seems the best way to do this, if not, would be to extend image and make a pseudo class "image control" using canvas/imagecanvas? Is it possible to extend a JPanel and set up a constructor for a class such as ImageIcon? The API from sun is less than helpful on details...as well as on most other class/instance methods - it's as if your expected to know exactly what they mean when they provide a terse explantion of instance/class functionality - a small gripe, but nonetheless it would make development exceedingly easier for newcomers if examples, and a better descriptor was added per class/method (aside from the obvious stuff like ".setBounds(),.setSize(), etc...")

Thanks! It's great to be here and that there is a friendly community for Java related development to turn to. Hopefully, within a year, I'll be able to contribute to helping others as well in a more knowledgeable way.

--Alex
[ May 28, 2004: Message edited by: shana turs ]
 
The moustache of a titan! The ad of a flea:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic