Click & drag on Label


#1

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?

thanks


#2

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)


#3

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.


#4

I created that using a custom Label with an invisible Slider

Rail


#5

Ah good tip!

 

I solved it with a mouseListener on the Labels I use for number boxes & overrided mouseDrag..ie 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);

       }
}