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);
}
Just use the setBounds attribute. Jtextfield. setBounds(x,x,x,x);
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 .
There are 4 types of text alignments which are left-aligned, center-aligned, right-aligned, and justified.
jTextField.setHorizontalAlignment(SwingConstants.RIGHT);
(JavaDoc)
This should align all text you entered in JTextField to right:
JTextField.setHorizontalAlignment(SwingConstants.RIGHT);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With