mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-14 15:57:12 -06:00
ScrollBar: preserve hover highlight while dragging even if mouse moves outside of scrollbar
This commit is contained in:
@@ -155,29 +155,42 @@ public class FlatScrollBarUI
|
|||||||
|
|
||||||
//---- class ScrollBarHoverListener ---------------------------------------
|
//---- class ScrollBarHoverListener ---------------------------------------
|
||||||
|
|
||||||
|
// using static field to disabling hover for other scroll bars
|
||||||
|
private static boolean isPressed;
|
||||||
|
|
||||||
private class ScrollBarHoverListener
|
private class ScrollBarHoverListener
|
||||||
extends MouseAdapter
|
extends MouseAdapter
|
||||||
{
|
{
|
||||||
@Override
|
|
||||||
public void mouseEntered( MouseEvent e ) {
|
|
||||||
hoverTrack = true;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited( MouseEvent e ) {
|
public void mouseExited( MouseEvent e ) {
|
||||||
hoverTrack = hoverThumb = false;
|
if( !isPressed ) {
|
||||||
repaint();
|
hoverTrack = hoverThumb = false;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved( MouseEvent e ) {
|
public void mouseMoved( MouseEvent e ) {
|
||||||
|
if( !isPressed )
|
||||||
|
update( e.getX(), e.getY() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed( MouseEvent e ) {
|
||||||
|
isPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased( MouseEvent e ) {
|
||||||
|
isPressed = false;
|
||||||
update( e.getX(), e.getY() );
|
update( e.getX(), e.getY() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update( int x, int y ) {
|
private void update( int x, int y ) {
|
||||||
boolean inThumb = thumbRect.contains( x, y );
|
boolean inTrack = getTrackBounds().contains( x, y );
|
||||||
if( inThumb != hoverThumb ) {
|
boolean inThumb = getThumbBounds().contains( x, y );
|
||||||
|
if( inTrack != hoverTrack || inThumb != hoverThumb ) {
|
||||||
|
hoverTrack = inTrack;
|
||||||
hoverThumb = inThumb;
|
hoverThumb = inThumb;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user