Placing figure in top-right corner of another
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:
- Write layout manager myself
- 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:
On the top-level container (JWindow, JDialog, JFrame, JApplet) add a glass pane and paint the icon there.
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.
精彩评论