public MyListCellRenderer() { myPanel = new JPanel(new BorderLayout()); myPanel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); myNameLabel = new JLabel(); myPanel.add(myNameLabel, BorderLayout.WEST); myPanel.add(new JLabel(" ")); myNSLabel = new JLabel(); myPanel.add(myNSLabel, BorderLayout.EAST); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Font font = scheme.getFont(EditorFontType.PLAIN); myNameLabel.setFont(font); myNSLabel.setFont(font); }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { XmlElementDescriptor descriptor = (XmlElementDescriptor) value; Color backgroundColor = isSelected ? list.getSelectionBackground() : list.getBackground(); myNameLabel.setText(descriptor.getName()); myNameLabel.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); myPanel.setBackground(backgroundColor); myNSLabel.setText(getNamespace(descriptor)); myNSLabel.setForeground(LookupCellRenderer.getGrayedForeground(isSelected)); myNSLabel.setBackground(backgroundColor); return myPanel; }