RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

Flickering of focusable tooltip

Open vbmacher opened this issue 4 years ago • 2 comments

Hi,

I wanted to resize font of the text area on a CTRL+{mouse wheel}. Important part is to show a tooltip with the zoom percent on a fixed location (or close to the mouse pointer, this doesn't matter).

I was successful with the resizing, but I'm having trouble with properly showing the tooltip - on a mouse wheel it is flickering. I use the following code:

TextEditorPane textPane = new TextEditorPane(RTextArea.INSERT_MODE, true);

FocusableTip zoomTip = new FocusableTip(textPane, null);
textPane.addMouseWheelListener(e -> {
    int wheelRotation = e.getWheelRotation();
    if (wheelRotation != 0 && (e.getModifiersEx() & CTRL_DOWN_MASK) != 0) {

        // font resizing
        Font font = textPane.getFont();
        int currentSize = font.getSize();
        float newSize = (wheelRotation > 0) ? Math.max(currentSize - 1, FONT_DEFAULT_SIZE) : (currentSize + 1);
        textPane.setFont(font.deriveFont(newSize));

        // now the tooltip!
        int percent = (int)(newSize / FONT_DEFAULT_SIZE * 100.0);
        zoomTip.toolTipRequested(e, percent + "%");
    }
});

Note that maybe I'm using the FocusableTip in a wrong way, but I cannot find proper usage of it (lack of documentation).

My analysis is as follows - the problem might be in the order of repaint events in Swing. Upon a font change the whole text area view is repainted (if the text is long enough) and this might happen after the tooltip is being painted. I think a double buffering of the tooltip might help.

EDIT: I'm using Linux, Java 11

vbmacher avatar Jun 24 '20 13:06 vbmacher

Thanks, I'll take a look. Also note I probably should add this as a built-in feature, at least the mouse wheel changing the font size, along with it firing an event to let folks do things like display a tool tip.

bobbylight avatar Aug 04 '20 03:08 bobbylight

Yes, very good idea. User should be able to enable/disable the behavior when constructing the text editor. Thanks!

vbmacher avatar Aug 04 '20 09:08 vbmacher