我被要求能够打印一个时尚的JComponent,所以它看起来很棒。不要问我什么是最棒的,因为我也不知道。
对于x和y格式的页面,JComponent都要求太大。我需要将相同的JComponent打印到许多在给定y坐标上拆分的页面中。
我已经尝试过缩放JComponent,但在选择给定的y坐标并使其看起来更好时遇到了问题。
我尝试将JComponent更改为给定的大小,但是给定的y坐标是有问题的,JComponent看起来不是很好,如果程序更改,我会遇到很多问题。
所以现在我坐在这里,不知道该做什么,因为网上似乎完全缺乏关于这个主题的教程……
Word和其他基于文本的程序是如何做到这一点的?
致以最好的问候,Skarion
发布于 2011-04-17 18:15:24
这是一个常见的问题,我必须说我已经面对过它了。这些教程对我很有用:
我希望它也能帮助你。
也许当你对你的问题有更多了解的时候,我可以提供更多的帮助。:)
EDIT1:
double scale = 1;
//scale only when component is wider then a page (page and component widths are doubles)
if(componentWidth > pageWidth)
scale = pageWidth/ componentWidth;
//I first calculate where each page should end
//...
//then when I paint a page I calculate translation over Y for each page
double translateY = 0;
//if page index grater then zero then take where the previous page ends
if(pageIndex > 0)
translateY = pageHeightEnds.get(pageIndex - 1);
//shift Graphic to line up with beginning of next page to print
g2.translate(0f, -translateY);
g2.setClip(0, (int) Math.round(translateY),(int) Math.round(pageWidth), (int) Math.round(currentPageWidth));
// scale the page so the width fits...
g2.scale(scala, scala);
componentToPaint.paint(g2); 祝你好运,波罗。
https://stackoverflow.com/questions/5692823
复制相似问题