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

user1951149 picture user1951149 · Jan 6, 2013 · Viewed 33.2k times · Source

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

            }

Answer

Mike picture Mike · Jan 6, 2013
jTextField.setHorizontalAlignment(SwingConstants.RIGHT);

(JavaDoc)