Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java images

 
a cccc
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi im a fairly new programmer to java and need a bit of help.

Im currenty using a java frame and drawing images onto it. I am now having a bit of difficulty adding a jpg image at a particular location.

private static Panel p = new Panel();
Icon icn = new ImageIcon(getClass().getResource("image.jpg"));

JLabel label3 = new JLabel(" ");
label3.setIcon(icn);
p.add(label3);
add("North",p);


The above creates a panel, adds a label(which contains the image i require), then adds this panel to the north of the screen. It works however i want to be able to place the image a speific location or coordinates(not just north,s,e,w), any ideas??
cheers
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, a. We like to keep things friendly around here so we ask that people use their real names, as detailed in our
naming policy. In short, your name must be a first name and last name, separated by a space and not obviously fake.
As for your question, Java was designed to be cross platform and the GUI model reflects that. We don't know if our code will be run on a desktop, a kiosk, or a phone, so the layout managers, properly used, collaborate to keep a GUI usable no matter where it is displayed. Using absolute coordinates won't be nearly as flexible, but if you insist, all you have to do is set the container's layout to null and use the component's setBounds method to position.
The Java Tutorial chapter on Laying Out Components goes into more detail on layout managers and absolute positioning.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!