Fabian Zeindl
Fabian Zeindl

Reputation: 5988

MouseClick on Label

I am trying to register a click on a label, but i can't get it to work.

So far I've tried to set the SelectionAdapter to the label but click-events aren't fired.

Upvotes: 4

Views: 4220

Answers (2)

user1438038
user1438038

Reputation: 6069

For sake of completeness, I'll just add this code sample:

label.addMouseListener(new MouseAdapter() {
   @Override
   public void mouseUp(MouseEvent event) {
      super.mouseUp(event);

      if (event.getSource() instanceof Label) {
         Label label = (Label)event.getSource();

         System.out.println("Label was clicked: " + label.getText());
      }
   }
});

Upvotes: 5

Gorkem Ercan
Gorkem Ercan

Reputation: 3226

Labels are not selectable Controls SelectionAdapter won't work for it. Try adding a MouseListener.

Upvotes: 6

Related Questions