I need to add items in a JtextArea and with its Description and a Price but i have a problem in aligning it. i want an output of this is like
Description
HTML In a JTextPane rather than JTextArea one could use HTML:
Description .... ...
With CSS styles the most beautiful, requiring some effort.
String.format With a fixed-size font (monospaced) in a JTextArea one can do:
txtArea.setFont(new Font("monospaced", Font.PLAIN, 12));
txtArea.append(String.format("%-30s %15s %10d\n", desc, price, quanty));
- %-30s left aligned string
- %15s right aligned string
- %10d right aligned integer
讨论(0)
- 热议问题