Results 1 to 3 of 3
  1. #1
    Zambash is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default How to move a JLabel?

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package javaapplication5;
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    /**
     *
     * @author Robert Herriott
     */
    public class NewClass {
            public static void main(String[] args) throws MalformedURLException {
    
            URL url = new URL("http://i293.photobucket.com/albums/mm46/Zambash/th_ThrowingAxe.gif");
            Icon icon = new ImageIcon(url);
            JLabel label = new JLabel(icon);
            label.setLocation(50, 50);
     
            JFrame f = new JFrame("Animation");
            f.add(label);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(800, 800);
            f.setVisible(true);
    
            label.setLocation(0, 0);
        }
    }
    I just want to change the location of "label" I tried using that setLocation() at the bottom and then about 5 million different combinations of repainting and validating the frame and the label and I've spent about 2 hours on something that should take 2 seconds. Someone just tell me, how the heck do I move a JLabel?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    Zambash is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    Found it, thanks. Just had to set content pane layout to null and then I can do whatever I want with my labels.
    Last edited by Zambash; 08-24-2011 at 07:52 PM.

Similar Threads

  1. how to move this image
    By melonka.sg in forum New To Java
    Replies: 1
    Last Post: 01-08-2011, 04:53 PM
  2. move object
    By melonka.sg in forum New To Java
    Replies: 3
    Last Post: 01-06-2011, 06:28 PM
  3. Help with Move Shape
    By romina in forum AWT / Swing
    Replies: 2
    Last Post: 12-09-2010, 03:25 AM
  4. Adding a JLabel to a JPanel - jlabel not showing
    By Bongeh in forum New To Java
    Replies: 17
    Last Post: 04-06-2010, 11:02 PM
  5. how can i move from Frame to another
    By the swan in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2009, 04:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •