I've tried looking but I can't seem to find a solution to my justification problem. I want all the transaction amounts, which turn up with 2 decimals digits, to be all justified to the right, however, nothing I try seems to work. This is the result:
Transaction temp;
String message = "";
for (int i = 0; i < checkAccnt.gettransCount(); i++)
{
temp = checkAccnt.getTrans(i);
message += String.format("%-10d", temp.getTransNumber());
message += String.format("%-10d", temp.getTransId());
message += String.format("%10.2f", temp.getTransAmount()) + '\n';
}
JOptionPane.showMessageDialog(null, message);
An alternative to using a fixed width font (as suggested in the comments) or different widgets with better alignment control (as suggested in a different answer) might be to replace the space characters in front of the digits with space characters that have the same width as the digits (if the font has a fixed width for digits, which the screenshot seems to support):
message += String.format("%-10d", temp.getTransNumber()).replace(' ', '\u2007');
See http://www.fileformat.info/info/unicode/char/2007/index.htm
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