Below example shows how to get X and Y coordinates of a JTextField Syntax: field=new JTextField("Get X and Y JTextField Example...
Below example shows how to get X and Y coordinates of a JTextField
Syntax:
field=new JTextField("Get X and Y JTextField Example");
int x =field.getX();
int y=field.getY();
getX and getY Example
/**
*
* @author Eric
* Blog:www.techoverload.net
*This Example shows how to get JTextField X and Y coordinates
*/
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Dimension;
import java.awt.FlowLayout;
public class JTextFieldExample extends JFrame{
public JTextField field;
JTextFieldExample()
{
super("JTextField methods");
setLayout(new FlowLayout());
//create JTextField object
field=new JTextField("Get X and Y JTextField Example");
int x =field.getX();
int y=field.getY();
System.out.println("X coordinate for JTextField is "+x);
System.out.println("Y coordinate for JTextField is "+y);
add(field);
setSize(new Dimension(300,300));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[])
{
new JTextFieldExample();
}
}