将图形放置在另一个图形的右上角

发布于 2024-08-25 23:33:33 字数 357 浏览 6 评论 0原文

我希望子图 (org.eclipse.draw2d.Figure) 相对于父图的右上角(我想放置一些小图标,即 ImageFigure,距顶部和右侧边框 12 个像素)。是否有现有的布局管理器可以以这种方式布局子项?

org.eclipse.draw2d.XYLayout 无法测量相对于左上角以外的角的位置。

当然,我可以:

  1. 自己编写布局管理器,
  2. 每次更改父级的边界时(在父级layout()方法中),布局子级都会显示出来。

但是,我想知道某些现有的布局管理器是否提供该功能。

请注意,该问题是关于 Eclipse GEF,而不是关于 SWT/JFace 或 Swing。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

善良天后 2024-09-01 23:33:33

许多布局允许您将组件放置在右侧。 FlowLayout、BoxLayout、GridBagLayout。使用 FlowLayout 可能是最简单的。您只需将水平和垂直间隙设置为 12 并使用右对齐即可解决您的问题。

或者,您可以向组件添加一个 EmptyBorder,并在顶部/右侧插入 12,以确保其精确放置在您想要的位置。

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.

嘿咻 2024-09-01 23:33:33

没有一个标准布局管理器会为您做这件事。

我可以想到两种可能性:

  1. 在顶级容器(JWindow、JDialog、JFrame、JApplet)上添加一个玻璃窗格并在那里绘制图标。

  2. 创建一个用于绘制图标的边框。我更喜欢这个想法,因为它可以与任何 JComponent 一起使用,并且很明显它是组件上的装饰。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文