14

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);

            }
Endery
  • 1,090
  • 17
  • 31
user1951149
  • 155
  • 1
  • 2
  • 8

3 Answers3

35
jTextField.setHorizontalAlignment(SwingConstants.RIGHT);

(JavaDoc)

Mike
  • 2,434
  • 1
  • 16
  • 19
4

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

JTextField.setHorizontalAlignment(SwingConstants.RIGHT);
Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
Pradeep Simha
  • 17,683
  • 18
  • 56
  • 107
1

it works the same as SwingConstants.RIGHT but thought if we know we are working with JTextField then be specific.

tf_rsfig.setHorizontalAlignment(JTextField.RIGHT);

Bhavin
  • 11
  • 2