• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can i postion the cursor.................

 
kishore mantri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys!
i have some problem with the cursor.
i made a calculator.but i want the cursor to take the input from right hand side and move to left hand side as the input are entered.
if u got my question please reply me other wise tell me that u couldn't get me so that i can explain u clearly.
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishore,
I found this quote at the Java Developer Connection. Hope it helps you.
Stephanie

Hi,
As far as I know, you can not right-align text in a text field using the java.awt.TextField class. However, you can use the javax.swing.JTextField class to right-align text in a text field. This class has a method public void setHorizontalAlignment(int alignment) which sets the horizontal alignment of the text. Valid keys are JTextField.LEFT(the default), JTextField.CENTER, and JTextField.RIGHT.
The following piece of code does what you want :
import javax.swing.JTextField ;
import javax.swing.JFrame ;
import java.awt.FlowLayout ;
public class test extends JFrame
{
public test ()
{
getContentPane().setLayout(new FlowLayout()) ;
JTextField tf = new JTextField("Valerie", 12) ;
tf.setHorizontalAlignment(JTextField.RIGHT) ;
getContentPane().add(tf) ;
setSize(200,200) ;
setVisible(true) ;
}
public static void main (String [] args)
{
test t = new test() ;
}
}
I hope this helps,
jeromeV
Sun Microsystems, Inc.
 
kishore mantri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi garasson!
thank u for ur reply!!
kishore
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic