Click & drag on Label


Hi - I have Labels setup as number boxes which the user can click & change value. I want to be able to click and drag up / down on the label to increase / decrease the value. How would I go about this?



Surely would make more sense to use a Slider, which already has that functionality?

(But you could of course just add a mouselistener to the Label and respond to mouse drags appropriately)


true, but I only want a number display + the ability to click drag to increase / decrease the variable, and not any slider track or anything.


Thanks, I'll look at the mouseListener route.


I created that using a custom Label with an invisible Slider



Ah good tip!


I solved it with a mouseListener on the Labels I use for number boxes & overrided something like:


void ParentComponent::mouseDrag(const MouseEvent& e)


        if(e.eventComponent == LabelNumberBox)


            double changeVal = 0.0;

            if(e.getDistanceFromDragStartY() < 0) changeVal = -0.5; //up

            if(e.getDistanceFromDragStartY() > 0) changeVal = +0.5; //down

            numberBoxValue01 += changeVal;

            LabelNumberBox->setText((String)numberBoxValue01, dontSendNotification);