开发者

Placing figure in top-right corner of another

开发者 https://www.devze.com 2022-12-23 05:06 出处:网络
I want child figure (org.eclipse.draw2d.Figure) to be relative to the top-right corner of the parent (I want place some small icon, which will be ImageFigure, to be 12 pixels from top and right border

I want child figure (org.eclipse.draw2d.Figure) to be relative to the top-right corner of the parent (I want place some small icon, which will be ImageFigure, to be 12 pixels from top and right borders). Is there an existing layout manager that can layout child this way?

The org.eclipse.draw2d.XYLayout is not capable of measuring position relative to corner other than top-left.

Of course, I can:

  1. Write layout manager myself
  2. Layout children figure every time bounds are change开发者_高级运维d for the parent (in parent layout() method).

However, I would like to know if some existing layout manager provides that functionality.

Note that question is about Eclipse GEF, not bare SWT/JFace or Swing.


Many layouts allow you to position a component on the right. FlowLayout, BoxLayout, GridBagLayout. Using a FlowLayout would probably be the easiest. You can just set the horizontal and vertical gaps to 12 an use right alignment and it should solve your problem.

Or else you could add an EmptyBorder to the component with a top/right insert of 12 to make sure is is placed precisely where you want it.


None of the standard layout managers will do that for you.

I can think of 2 possibilities:

  1. On the top-level container (JWindow, JDialog, JFrame, JApplet) add a glass pane and paint the icon there.

  2. Create a Border that will paint the icon. I rather like this idea as it will work with any JComponent and it is clear that it is a decoration on the component.

0

精彩评论

暂无评论...
验证码 换一张
取 消