Skip to content
This repository
Browse code

popup menu and select background colour

  • Loading branch information...
commit d2ff54aedff6d01643133dde5c5743fdf562eb35 1 parent 582eb23
Mattias Andrée [mˈa.tːiː.ˌas ˈanː.drˌeː] authored

Showing 1 changed file with 40 additions and 1 deletion. Show diff stats Hide diff stats

  1. +40 1 src/cnt/interfaces/gui/UserList.java
41 src/cnt/interfaces/gui/UserList.java
@@ -44,6 +44,35 @@ public UserList()
44 44 this.setBackground(Color.BLACK);
45 45 pane.setBackground(Color.BLACK);
46 46 this.list.setBackground(Color.BLACK);
  47 + this.list.setSelectionBackground(new Color(16, 16, 100));
  48 +
  49 + this.popup = new JPopupMenu();
  50 + this.popup.add(this.menuFriend = new JMenuItem("Add to friend list"));
  51 +
  52 +
  53 + this.list.addMouseListener(new MouseAdapter()
  54 + {
  55 + /**
  56 + * {@inheritDoc}
  57 + */
  58 + public void mouseReleased(final MouseEvent e)
  59 + {
  60 + // e.isPopupTrigger() returns false
  61 + if (e.getButton() == 3 /*right*/)
  62 + UserList.this.popup.show(e.getComponent(), e.getX(), e.getY());
  63 + }
  64 + });
  65 +
  66 + this.menuFriend.addActionListener(new ActionListener()
  67 + {
  68 + /**
  69 + * {@inheritDoc}
  70 + */
  71 + public void actionPerformed(final ActionEvent e)
  72 + {
  73 + System.err.println("[Add to friend list] click");
  74 + }
  75 + });
47 76 }
48 77
49 78
@@ -51,12 +80,22 @@ public UserList()
51 80 /**
52 81 * The list component
53 82 */
54   - private final JList list;
  83 + private final JList list; // Generics was added to JList in Java 7. We can not use it because CSC only have Java 6 installed.
55 84
56 85 /**
57 86 * The list's model
58 87 */
59 88 private final DefaultListModel model;
60 89
  90 + /**
  91 + * The popup menu
  92 + */
  93 + private final JPopupMenu popup;
  94 +
  95 + /**
  96 + * The “Add to friend list” menu item
  97 + */
  98 + private final JMenuItem menuFriend;
  99 +
61 100 }
62 101

0 comments on commit d2ff54a

Please sign in to comment.
Something went wrong with that request. Please try again.