Disable items in JList

前端 未结 4 1298
清歌不尽
清歌不尽 2020-11-29 10:16

I\'m using a JList as part of a wizard to display all the steps to be performed (it also allows clicking on a step to go to it). Some steps will not always be needed, based

4条回答
  •  攒了一身酷
    2020-11-29 11:04

    I wanted a JList with cells that couldn't be select AND were transparent. So here's what I did:

    class DisabledItemListCellRenderer extends JLabel implements ListCellRenderer {
    
        private static final long serialVersionUID = 1L;
    
        public DisabledItemListCellRenderer() {
            setOpaque(false);
        }
    
        @Override
        public Component getListCellRendererComponent(JList list, Object value,
                int index, boolean isSelected, boolean cellHasFocus) {
            String txt = (String) value;
            setText(txt);
    
            return this;
        }       
    }
    
        

    提交回复
    热议问题