opened
UltimateYZ
username_0
Hi JFormDesigner,

I'm trying to add a simple mouse event (mouse Pressed) to change the thumbColor from the user input, in my flatscrollbarUI class but it doesn't work... Is there a convenient way to do it? Pls help...
Is there a simple way to add mouse event on flatlaf scrollbar component?
issue
created
DevCharly
username_1
You can simply add the mouse listener to the `JScrollBar`. See:
https://github.com/JFormDesigner/FlatLaf/blob/211030b5b6b0beac5a60b954ea89c9a681b77d94/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java#L101

You probably have to change `hoverThumbColor` because this color is used when the mouse pointer is over the thumb.

Or override method `getThumbColor`:
https://github.com/JFormDesigner/FlatLaf/blob/211030b5b6b0beac5a60b954ea89c9a681b77d94/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java#L285-L289

And maybe invoke `scrollbar.repaint()` ?

Anyway, I think it would be nice if `FlatScrollBarUI` would support some "pressed" colors out of the box. This is now missing. I'll add them in the next days...
comment
created
UltimateYZ
username_0
Thanks, I really appreciated it.
comment
closed
UltimateYZ
username_0
issue
reopened
UltimateYZ
username_0
Hi JFormDesigner,

I'm trying to add a simple mouse event (mouse Pressed) to change the thumbColor paint (momentarily) from the user's mice left button input, in my flatscrollbarUI class but it doesn't work... Is there a convenient way to do it?

 Pls help...
Is there a simple way to add mouse event on flatlaf scrollbar component?
issue
created
UltimateYZ
username_0
Well, I tried to use repaint() method... 

![Screenshot from 2020-06-17 20-21-23](https://user-images.githubusercontent.com/55871338/84934932-4bd69500-b0d8-11ea-9bfc-e9c47f5b4323.png)
comment
created
DevCharly
username_1
@username_0 `g.setColor(...)` should be invoked only in paint methods just before painting lines, rectangles, text, etc. Not sure where the `g` comes from in your `mousePressed` method.

Try following:
~~~java
hoverThumbColor = Color.red;
scrollbar.repaint();
~~~

BTW I've pushed commit fe15f44e967c72244f770a630d0ac604be75e451 to master branch that implements pressed colors for ScrollBars. By default the thumb is made slightly darker/lighter when pressed.

You can use own colors with:
~~~java
UIManager.put( "ScrollBar.pressedThumbColor", Color.red );
~~~

If you like to change the pressed color dynamically, you can override method `FlatScrollBarUI.getThumbColor`:
~~~java
@Override
protected Color getThumbColor( JComponent c, boolean hover, boolean pressed ) {
    if( pressed )
        return anyColor;
    return super.getThumbColor( c, hover, pressed );
}
~~~
comment
created
UltimateYZ
username_0
Thanks for the help.
comment
closed
UltimateYZ
username_0
issue