tags:

views:

27

answers:

2

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 changed 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.

+1  A: 

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.

camickr
+1  A: 

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.

Devon_C_Miller