通过覆盖 `createCell` 将图像组件添加到表格单元格
我正在使用 LWUIT 并使用 Table
显示数据,例如航班信息! 我不喜欢用文字来写航空公司,而是用图标来代替它们。 因此,我需要重写 Table
的 protected Component createCell(Object value, Final int row, Final int column, boolean editable)
方法。
这就是我的实现方式:
初始化
imgAln[i]=null;
try {
imgAln[i] = Image.createImage(strPathToImage[i]);
//e.g /uta.png,/somonair.png and so on
lAln[i] = new Label(imgAln[i]);
} catch (IOException e) { }
创建表对象
Table table = new Table(model) {
protected Component createCell(Object value, final int row,
final int column, boolean editable) {
final Component c = super.createCell(value, row, column, editable);
if (column == 6) {
return lAln[value]; //it does not work here
}
}
};
需要帮助将图像添加到表单元格!
有例子吗???欢迎链接!
I am using LWUIT and showing data with Table
, say, flight information!
Instead of writing air companies with text I just like to replace them with icons.
So, I need to override protected Component createCell(Object value, final int row, final int column, boolean editable)
method of Table
.
This is how I've implemented:
Initializing
imgAln[i]=null;
try {
imgAln[i] = Image.createImage(strPathToImage[i]);
//e.g /uta.png,/somonair.png and so on
lAln[i] = new Label(imgAln[i]);
} catch (IOException e) { }
Creating Table object
Table table = new Table(model) {
protected Component createCell(Object value, final int row,
final int column, boolean editable) {
final Component c = super.createCell(value, row, column, editable);
if (column == 6) {
return lAln[value]; //it does not work here
}
}
};
need help to add Image to table cell!!!
Is there any example??? links are welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
createCell(...)
实现中的问题是,当column 不是 6< 时,它不会返回
super.createCell(...)
/代码>。此外,您的标签数组 (lAln
) 可能无法正确创建。请尝试下面的实现,但请确保将适当的图像名称存储在表模型的第 0 列
中。这应该可以解决问题:
注意:如果您在第 0 列中看到的是名称而不是图像,则意味着图像路径不正确,请修复它以查看图像。
您是否设法查看了项目
LWUITDemo
中的TableLayoutDemo.java
?如果我没记错的话,这是捆绑的下载包LWUIT1.5.zip
(或者你可以随时用谷歌搜索它)。如果您需要更具体的帮助,请告诉我。
The problem in your
createCell(...)
implementation is that it does not return thesuper.createCell(...)
when thecolumn is not 6
. Also your array of labels (lAln
) may not be properly created. Try my implementation below, but make sure you store the appropriate image name in the table models'column 0
.This should solve it:
NOTE: If you see the names instead of images in column 0 it means the image path is incorrect, fix it to see the images.
Did you manage to have a look at
TableLayoutDemo.java
in projectLWUITDemo
? If i remember it correct, this comes bundled download packageLWUIT1.5.zip
(or you can always google it).Let me know if you need more specific help.