Below code shows how to get JLabel coordinates using getX and getY methods. /** /** * * @author Eric * Blog:www.techoverload.net * ...
Below code shows how to get JLabel coordinates using getX and getY methods.
/** /** * * @author Eric * Blog:www.techoverload.net * */ import java.awt.Color; import javax.swing.JLabel; import javax.swing.JFrame; public class JLabelExample extends JFrame{ JLabelExample() { super("JLabel Example"); JLabel label=new JLabel("JLabel Example"); label.setBounds(40,30,200, 20); //methods to get Y and X coordinates int x=label.getX(); int y=label.getY(); System.out.println("X coordinate is "+x); System.out.println("Y coordinate is "+y); //======================================= add(label); setSize(300,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(null); setVisible(true); } public static void main(String args[]) { new JLabelExample(); } }