当前位置:编程学习 > JAVA >>

jlist设置CellRender后如何获取文本?

如题,我在Jlist的每一行插入了图标和文本后,怎么样获取到选中行的文本信息呢?如果用getSelectedValue()的话获取到的是一行的信息,而不是文本信息,请问怎样获取到文本信息呢?知道的告诉下,谢谢
渲染重新定义如下:
public class IconListItemRenderer extends JLabel implements ListCellRenderer
{
    private Border
        selectedBorder = BorderFactory.createLineBorder(Color.blue,1),
        emptyBorder = BorderFactory.createEmptyBorder(1,1,1,1);
    IconListItem item = new IconListItem(new ImageIcon("F:\\1.ico") , "aa") ;

    public Component getListCellRendererComponent(
                JList list,
                Object value,
                int index,
                boolean isSelected,
                boolean cellHasFocus)
        {
try
{
if(value  instanceof  IconListItem){
   item = (IconListItem)value;
}
}catch(Exception e){System.out.println("转换失败!");}

        this.setIcon(item.getIcon());
        this.setText(item.getText());



        if ( isSelected ) setBorder (selectedBorder);
        else setBorder(emptyBorder);
        return this;
    }
} --------------------编程问答-------------------- item类定义如下:
public class IconListItem
{
    public Icon icon;
    public String text;
    public IconListItem(Icon icon, String text)
    {
        this.icon = icon;
        this.text = text;
    }
    public IconListItem(IconListItem item)
    {
     this.icon = item.icon ;
     this.text = item.text ;
    }
    public Icon getIcon() { return icon;}
    public String getText() { return text;}
    public void setIcon(Icon icon){ this.icon = icon;}
    public void setText(String text){ this.text = text; }
}

请问怎么可以获取到jlist选中行的文本信息text呢? --------------------编程问答-------------------- --------------------编程问答-------------------- 同问同问啊、
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,