0
我有一個標準com.sun.lwuit.list
。我可以使用方法getSelectedItem
或getSelectedIndex
獲取所選項目。該項目是一張圖片和兩個標籤。我怎麼知道我是否點擊了圖片或其中一個標籤。我承認可以將click事件傳遞給子組件,或者可能存在一種通過當前鼠標座標查找組件的方法。LWUIT項目問題
public class NewsFeedListRender extends Container implements ListCellRenderer
{
private final Container newsFeedCont = new Container();
private final Container pictureCont = new Container();
private final Label name = new Label();
private final Label message = new Label();
private final Label picture = new Label();
private final Label data = new Label();
....
public NewsFeedListRender()
{
setLayout(new BorderLayout());
newsFeedCont.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
pictureCont.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Style s = name.getStyle();
s.setFont(font_large);
s = message.getStyle();
s.setFont(font_small);
s = data.getStyle();
s.setFont(font_mini);
.....
}
}
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
{
if (value instanceof MessageItem)
{
MessageItem newsFeedData = (MessageItem) value;
if (newsFeedData.getSender() != null)
{
if (newsFeedData.getSender().getName() != null)
name.setText(newsFeedData.getSender().getName()); //fixthis
}
else
{
name.setText("Unknown sender");
}
if(newsFeedData.getMessage() != null)
message.setText(newsFeedData.getMessage());
else
{
message.setText("Default message");
}
try
{
data.setText(newsFeedData.getDataReceive().toString());
}
catch (Exception e)
{
System.out.println(e.toString());
}
Image img = null;
img = newsFeedData.getSender().getIcon();
if(img != null)
{
picture.setIcon(img);
}
.......
我已經知道項目中包含哪些組件。我想知道如果我點擊圖片或其中一個標籤,該怎麼確定? –
AFAIK您添加列表的偵聽器。所以你不能在列表項中找到你點擊的組件。 – bharath