Пример #1
0
 @Override
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   Component ret;
   Icon icon;
   if (value instanceof Tool) {
     Tool t = (Tool) value;
     ret =
         super.getListCellRendererComponent(
             list, t.getDisplayName(), index, isSelected, cellHasFocus);
     icon = new ToolIcon(t);
   } else if (value == null) {
     ret = super.getListCellRendererComponent(list, "---", index, isSelected, cellHasFocus);
     icon = null;
   } else {
     ret =
         super.getListCellRendererComponent(
             list, value.toString(), index, isSelected, cellHasFocus);
     icon = null;
   }
   if (ret instanceof JLabel) {
     ((JLabel) ret).setIcon(icon);
   }
   return ret;
 }
Пример #2
0
 public void paintIcon(Component comp, Graphics g, int x, int y) {
   Graphics gNew = g.create();
   tool.paintIcon(new ComponentDrawContext(comp, null, null, g, gNew), x + 2, y + 2);
   gNew.dispose();
 }