7

2つの要素が架空の線に整列するテキストの行を作成するための最良の方法は何ですか?このように(ポイントをよりよく説明するために4行が与えられています):

   1. some random text
  34. some more random text
 764. here's even more random text
4594. it just never ends

架空の線は、ドット、またはドットの後のスペースを通過します。数字は右揃えで、テキストは左揃えです。

リストは要素が順番に並んでいない可能性があり、行間隔の設定には一定の制限があるため、使用したくありません。

4

1 に答える 1

18

最初の右揃えと最後の左揃えの2列のPdfPTableを使用できます。次に、セルのコンテンツにデザイナーのパディングを設定します。例えば:

PdfPTable tbl = new PdfPTable(2);
PdfPCell cell = new PdfPCell(new Phrase("1."));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell.disableBorderSide(Rectangle.BOX);
tbl.addCell(cell);
cell = new PdfPCell(new Phrase("some random text"));
cell.disableBorderSide(Rectangle.BOX);
tbl.addCell(cell);
cell = new PdfPCell(new Phrase("34."));
cell.disableBorderSide(Rectangle.BOX);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
tbl.addCell(cell);
cell = new PdfPCell(new Phrase("some more random text"));
cell.disableBorderSide(Rectangle.BOX);
tbl.addCell(cell);

セルの境界線が無効になっていることがわかります(disableBorderSideメソッド)。setMinimumHeightメソッドを使用してセルの最小の高さを調整することもできます。

于 2012-10-30T06:49:15.053 に答える