Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust alignment to right for a text entered in the JTextField

I want to set the alignment of my text to right. Actually the fields are related to currency so if it starts from right, it will look good.

PreparedStatement stmt1 = con.prepareStatement("select sum(tv)as totalsum from mut_det WHERE rm_id = ?");
            ResultSet rs1;
            String rm1 = tf_rm_id.getText().trim();
            stmt1.setInt(1, Integer.parseInt(rm1));
            rs1 = stmt1.executeQuery();
            while (rs1.next()) {
                String text = rs1.getString("totalsum");
                tf_rsfig.setText(text);

            }
like image 910
user1951149 Avatar asked Jan 06 '13 15:01

user1951149


People also ask

How do I center align text in JTextField?

Just use the setBounds attribute. Jtextfield. setBounds(x,x,x,x);

How do you align text?

Align the text left or right Select the text that you want to align. On the Home tab, in the Paragraph group, click Align Left or Align Right .

What are the text alignment options?

There are 4 types of text alignments which are left-aligned, center-aligned, right-aligned, and justified.


2 Answers

jTextField.setHorizontalAlignment(SwingConstants.RIGHT);

(JavaDoc)

like image 81
Mike Avatar answered Oct 10 '22 20:10

Mike


This should align all text you entered in JTextField to right:

JTextField.setHorizontalAlignment(SwingConstants.RIGHT);
like image 4
Pradeep Simha Avatar answered Oct 10 '22 20:10

Pradeep Simha