简体   繁体   中英

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

            }
jTextField.setHorizontalAlignment(SwingConstants.RIGHT);

JavaDoc

这应该将您在JTextField中输入的所有文本与右对齐:

JTextField.setHorizontalAlignment(SwingConstants.RIGHT);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM