最近在模仿QQ的登录界面,QQ中输入账号的地方有以前登录过的QQ号列表,当鼠标移到某一项上时后面出现一个用于删除账号的小叉,同时该项背放大并突出显示,请问这种效果怎么做?

解决方案 »

  1.   

    自己写JComboBox的render,public class MyComboRenderer extends JPanel implements ListCellRenderer
    {
    ...
    public Component getListCellRendererComponent(JList list, Object obj, int row, boolean sel, boolean hasFocus)
     {
    ...
    return this;
    }
    ...
    }JComboBox jcb = new JComboBox();
    jcb.setRenderer(new MyComboRenderer());
      

  2.   

    我重写了JComboBox的render,但是没能实现我要的功能,【focusforce】能不能帮我指点下,下面两行红色的代码是我想用来改变选项大小的,没有效果,请赐教!!!
    另外请问一个问题,我想给每一个项添加一个鼠标进入事件,该怎么写???public class ComboBoxRenderer implements ListCellRenderer{
    protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();   
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index,   
          boolean isSelected, boolean cellHasFocus) {
        Font theFont = null;   
        Color theForeground = null;   
        Icon theIcon = null;   
        String theText = null; 
        
        JLabel render=(JLabel)defaultRenderer.getListCellRendererComponent(list, value,
         index, isSelected, cellHasFocus);
        if(value instanceof ComboBoxItem){
         ComboBoxItem item=(ComboBoxItem)value;
         theFont=item.getFont();
         theForeground=item.getColor();
         theIcon=item.getIconItem();
         theText=item.getStrItem();
        }else{
         theFont=list.getFont();
         theForeground=list.getForeground();
         theText="";
         theIcon=null;
        }
        
        if(!isSelected){
         render.setForeground(Color.BLACK);
         render.setPreferredSize(new Dimension(100,30));
        }else{
         render.setBackground(new Color(55,142,206));
         render.setPreferredSize(new Dimension(100,80));
        }
        if(theIcon != null){
         render.setIcon(theIcon);
        }
        render.setText(theText);
        render.setFont(theFont);
        
        return render;
    }}
      

  3.   

    注意:我说的是鼠标进入就能触发的事件,而不是鼠标点击的事件,actionPerformed方法在一开始显示jcombobox就触发了,还没等我用鼠标进入item,而itemStateChanged要item改变后触发(需要点击),我想要刚生成窗口时有个jcombobox,里面有几个item,鼠标进入某个Item是菜触发事件
      

  4.   

    在获取 焦点的事件 中显示jcombobox