简体   繁体   English

Draw2d:包含RectangleFigure有时会在缩放时切断文本。 (含图片)

[英]Draw2d: Containing RectangleFigure will sometimes cuts off text when zoomed. (Pictures included)

In my program I have a bunch of RectangleFigures where each figure holds text. 在我的程序中,我有一堆RectangleFigures,其中每个图形都包含文本。 The text is held in a TextFlow which is held by FlowPage to allow word wrapping. 文本保存在由FlowPage保留的TextFlow中,以允许自动换行。 RectangleFigure then uses getPrefferedSize() to make itself just big enough to hold it's text (using a fixed width). 然后,RectangleFigure使用getPrefferedSize()使自身足够大以容纳其文本(使用固定宽度)。

These RectangleFigures are held by a ScalableLayeredPane. 这些RectangleFigures由ExpandableLayeredPane保存。 The problem rises when I try to zoom by calling setScale(). 当我尝试通过调用setScale()进行缩放时,问题就出现了。 Most of the time it works fine but occasionally the ends of the text will be cut off. 在大多数情况下,它工作正常,但有时文本的结尾会被截断。 If I zoom again the figure will correct itself. 如果我再次放大,该数字将自行校正。 I should also say that I have tested my program using Figure instead of RectangleFigure with the same result. 我还应该说我已经使用Figure而不是RectangleFigure测试了程序,结果相同。

Has anyone dealt with this bug before and can shed some light on why this is happening and/or know of any workarounds? 以前有没有人处理过此错误,并且可以弄清为什么会发生此错误和/或知道任何解决方法?

I havn't included any code because this is a rather large program and relevant chunks of code are spread out. 我没有包含任何代码,因为这是一个相当大的程序,并且相关的代码块已散布开来。 But if you would like to see the code let me know and I will try piecing it together. 但是,如果您想查看代码,请告诉我,我将尝试将其拼合在一起。

在此处输入图片说明

I was holding the text inside a Figure and that was the Figure I was calling getPrefferedSize() on. 我将文本保存在Figure中,这就是我调用getPrefferedSize()的Figure。 But I then put that Figure(lets call it textFigure) inside a second Figure(called containerFigure). 但是,然后我将那个Figure(让我们将其称为textFigure)放入第二个Figure(称为containerFigure)中。 I was essentially doing the equivalent of containerFigure.setSize(textFigure.getPrefferedSize()). 我实质上是在做与containerFigure.setSize(textFigure.getPrefferedSize())等效的事情。

You're probably wondering why I was doing that. 您可能想知道为什么我要这么做。 Well originally I planned on having containerFigure hold multiple things instead of just textFigure. 好吧,最初我计划让containerFigure容纳多个内容,而不仅仅是textFigure。 I ended up coding it differently but forgot about the unnecessary extra layer. 我最终对其进行了不同的编码,但忘记了不必要的额外层。

So even though containerFigure was technically the size it needed to be scaling caused problems. 因此,即使从技术上说,containerFigure的大小仍然需要缩放以引起问题。 But when I removed containerFigure and started placing textFigure directly on the screen this bug was fixed. 但是,当我删除containerFigure并开始直接在屏幕上放置textFigure时,此错误已修复。

This is a fairly specific error on my part so I don't know how much help this will be to others. 就我而言,这是一个相当具体的错误,所以我不知道这会对他人有多大帮助。 To make it more broad if you're having some kind of sizing issue just check to see how the size of parent Figures are being set. 如果您遇到某种尺寸问题,要使其更广泛,只需检查一下如何设置父图形的大小即可。 Using sizes from child Figures might be incorrect and/or causing problems. 使用子图的尺寸可能不正确和/或引起问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM