using Painter

28 views
Skip to first unread message

Bryan Buchanan

unread,
Jan 19, 2017, 1:06:36 AM1/19/17
to CodenameOne Discussions
I'm using a Painter to display a validation hint, similar to the example in the API docs.

This is the code that actually paints the image:

    private void paintMe(Graphics g, Component comp) {

        int xpos = comp.getAbsoluteX();
        int ypos = comp.getAbsoluteY();
        float width = comp.getWidth();
        xpos += Math.round(width);
        xpos -= 28;
        ypos -= 28;
        g.drawImage(image, xpos, ypos);

    }


Which works fine, as per the first screen shot. However, when I scroll up, the component is hidden by the heading component, but the glass pane doesn't know that. How can I figure out whether I should render the image ?
device-2017-01-19-155644.png
device-2017-01-19-155705.png

Shai Almog

unread,
Jan 20, 2017, 12:00:08 AM1/20/17
to CodenameOne Discussions
I've ran into that to in the input demo in the kitchen sink with the standard validation code. We need a good way to detect that, can you file an issue on this

Bryan Buchanan

unread,
Jan 20, 2017, 2:53:39 AM1/20/17
to CodenameOne Discussions
I solved it by a bit of hack, but it seems to work OK. In the attached file, when I instantiate my Painter, I save

top = f.getTitleComponent().getPreferredSize().getHeight();

and in the paint method

if (ypos < top) return;.
BJBValidatePainter.java
Reply all
Reply to author
Forward
0 new messages