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
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.