blu*_*sky 1 blackberry java-me
我正在向VerticalFieldManager添加字段.有没有在字段之间添加垂直间距的方法?
有几个解决方案,一个是你可以创建一个自定义字段作为其他字段之间的间隔.
private static class SpacerField extends Field
{
private int spacerWidth;
private int spacerHeight;
private SpacerField(int width, int height) {
spacerWidth = width;
spacerHeight = height;
}
protected void layout(int width, int height) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
protected void paint(Graphics g) {
// nothing to paint; this is a blank field
}
public int getPreferredHeight() {
return spacerHeight;
}
public int getPreferredWidth() {
return spacerWidth;
}
}
//...
// Usage
add(new LabelField("Before Spacer"));
add(new SpacerField(0, 100));
add(new LabelField("After Spacer"));
Run Code Online (Sandbox Code Playgroud)
设置包含字段的填充或边距是另一种解决方案.您认为这是管理事物的最佳方式取决于您.