用于触摸屏的自定义 ObjectChoiceField
我编写了自定义 ObjectChoiceField。 为了拉伸 ComboBox 屏幕的整个宽度。 该类如下所示:
public class ComboBox extends ObjectChoiceField {
private final int PADDING_HEIGHT = 20;
private final int width;
private final int height;
public ComboBox(Object[] choices, int width) {
super("", choices, 0, FIELD_LEFT);
this.width = width;
this.height = getFont().getHeight() + PADDING_HEIGHT;
this.setMinimalWidth(width);
}
public int getPreferredHeight() {
return height;
}
public int getPreferredWidth() {
return width;
}
protected void layout(int w, int h) {
setExtent(width, height);
}
public void getFocusRect(XYRect rect) {
rect.set(getFont().getAdvance(getLabel()), 0, width, height);
}
}
它可以在模拟器 9700 上运行,但不能在 9800 上运行。我看到抛出下一个堆栈跟踪:
C3CD62E3320B498 time: Wed Mar 23 15:10:29 2011 severity:1 type:3 app:Java Exception data:
IllegalArgumentException
No detail message
net_rim_cldc-13(4C48DD41)
Graphics
<private>
0x2726
net_rim_cldc-13(4C48DD41)
Graphics
tileRop
0x1C92
net_rim_cldc-19(4C48DD41)
BitmapBackground
draw
0xC4F
net_rim_cldc-16(4C48DD41)
ChoiceBox
draw
0x42AE
net_rim_cldc-16(4C48DD41)
ChoiceField
paint
0x55B0
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-19(4C48DD41)
VerticalFieldManager
subpaint
0xC6F0
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-19(4C48DD41)
VerticalFieldManager
subpaint
0xC6F0
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-13(4C48DD41)
Manager
subpaint
0x72C2
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-13(4C48DD41)
Manager
subpaint
0x72C2
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-14(4C48DD41)
Screen
paint
0x3725
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x
也许这是由于我使用构建项目 bb 工具的事实... 您有如何解决的想法吗?
I wrote my custom ObjectChoiceField.
In order to stretch the full width of ComboBox screen.
The class is presented below:
public class ComboBox extends ObjectChoiceField {
private final int PADDING_HEIGHT = 20;
private final int width;
private final int height;
public ComboBox(Object[] choices, int width) {
super("", choices, 0, FIELD_LEFT);
this.width = width;
this.height = getFont().getHeight() + PADDING_HEIGHT;
this.setMinimalWidth(width);
}
public int getPreferredHeight() {
return height;
}
public int getPreferredWidth() {
return width;
}
protected void layout(int w, int h) {
setExtent(width, height);
}
public void getFocusRect(XYRect rect) {
rect.set(getFont().getAdvance(getLabel()), 0, width, height);
}
}
It is works on simulator 9700, but does not work on 9800. I see throws next stacktrace:
C3CD62E3320B498 time: Wed Mar 23 15:10:29 2011 severity:1 type:3 app:Java Exception data:
IllegalArgumentException
No detail message
net_rim_cldc-13(4C48DD41)
Graphics
<private>
0x2726
net_rim_cldc-13(4C48DD41)
Graphics
tileRop
0x1C92
net_rim_cldc-19(4C48DD41)
BitmapBackground
draw
0xC4F
net_rim_cldc-16(4C48DD41)
ChoiceBox
draw
0x42AE
net_rim_cldc-16(4C48DD41)
ChoiceField
paint
0x55B0
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-19(4C48DD41)
VerticalFieldManager
subpaint
0xC6F0
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-19(4C48DD41)
VerticalFieldManager
subpaint
0xC6F0
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-13(4C48DD41)
Manager
subpaint
0x72C2
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-13(4C48DD41)
Manager
subpaint
0x72C2
net_rim_cldc-13(4C48DD41)
Manager
<private>
0x91C8
net_rim_cldc-13(4C48DD41)
Manager
paint
0x7BA3
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x6CF5
net_rim_cldc-13(4C48DD41)
Manager
paintSelf
0x7C14
net_rim_cldc-13(4C48DD41)
Manager
paintChild
0x7040
net_rim_cldc-14(4C48DD41)
Screen
paint
0x3725
net_rim_cldc-12(4C48DD41)
Field
paintSelf
0x
Perhaps this is due to the fact that I use to build the project bb tools...
Do you have ideas how to fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要从布局方法中调用 super.layout(w,h) ,以便 ObjectChoiceField 可以正确设置其内部状态。在 super.layout 之后,您可以进行所需的任何调整。
You need to call super.layout(w,h) from your layout method, so the ObjectChoiceField can set its internal state correctly. After super.layout, you can then make any adjustments you need.
布局导致了问题。如果你删除它,它就会起作用。
也许你可以设置宽度,但我不确定高度。
layout is causing the problem. If you remove it, it works.
Maybe you can set width but I am not sure for height.