简体   繁体   English

布局自定义按钮

[英]Layouting custom buttons

I am trying to create buttons shaped as in the following picture: 我正在尝试创建如下图所示的按钮: Powerpoint箭头按钮

This works pretty well by doing the following: 通过执行以下操作可以很好地工作:

class ArrowButton extends Composite {
    ArrowButton(Composite parent, int style) {
        [...]
        setRegion(customRegion);
    }
}

addStuff(Composite parent) {
    ArrowButton b = new ArrowButton(parent, SWT.NONE);
    b.setBounds(x, y, width, height);
}

However, I want to use a layout manager to layout these buttons. 但是,我想使用布局管理器来布局这些按钮。 Ideally, the buttons are layouted on a standard size, after which they can still paint outside of this region. 理想情况下,按钮按标准尺寸布置,之后它们仍然可以在该区域之外进行涂漆。

Is this at all possible? 这是可能吗? How can I do this? 我怎样才能做到这一点?

Layout managers have two functions: calculating the size of the composite that they are applied to and setting the bounds of the composite's children. 布局管理器有两个功能:计算应用它们的复合材料的大小,以及设置复合材料子元素的边界。 Given the relative simplicity of your requirements (line up buttons horizontally) I'd say that you're better off doing the layout yourself (rather than trying to hack an existing implementation). 鉴于您的要求相对简单(水平排列按钮)我会说你最好自己做布局(而不是试图破解现有的实现)。 You can always put your code into a delegate behind the Layout interface, if that feels better. 如果感觉更好,您可以随时将代码放在Layout界面后面的委托中。

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

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