Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Print Two Different Text Alignment on same line ? For invoice #27

Open
devaliakbar opened this issue Dec 14, 2019 · 2 comments
Open

Comments

@devaliakbar
Copy link

No description provided.

@devaliakbar
Copy link
Author

@slametbsan
Copy link

slametbsan commented Jul 16, 2020

this what i do, create padding method (padRight, padLeft, padCenter) with value of text width, in my case 32 characters. when they hit 32-characters, automatically move to next line.

   msg.append(padRight(nf.format(td.getHarga()), 14));  //harga satuan
   msg.append(padRight("x" + String.valueOf(td.getQty()), 4)); //qty
   msg.append(padLeft(nf.format(td.getSubtotal()), 14));   //sub-total

and the method are:

public static String padLeft(String s, int i){
    String leftPadded;
    leftPadded = String.format("%"+i+"s", s);
    return leftPadded;
}
public static String padRight(String s, int i){
    String rightPadded;
    rightPadded = String.format("%-"+i+"s", s);
    return rightPadded;
}
public static String padCenter(String s, int max){
    String centered;
    int i,h;
    h = (max-s.length())/2;
    //Log.i("cek 1", "Nilai h="+h+", max karakter="+max+", panjang teks="+s.length());
    i = s.length() + h;
    centered = String.format("%"+i+"s", s) + addSpace(h);
    return centered;
}

hope it's give you a picture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants