Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35258

Making a cross-hair visible

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.java.programmer
Subject Making a cross-hair visible
Date Thu, 11 Aug 2016 23:14:34 +0200
Organization Decebal Computing
Lines 32
Message-ID <87a8gjm2it.fsf@Equus.decebal.nl> (permalink)
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="28457"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kZG3dTUqrvqYO+lX6Y9F20LQx4+nB5eQ="
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
X-Homepage http://www.decebal.nl/
Cancel-Lock sha1:nkzNls50JsMOBgOsD4Hj0W4MfHc= sha1:WH/6vhoUKvaHshw70lOSui9YSrY=
Xref csiph.com comp.lang.java.programmer:35258

Show key headers only | View raw


I am dabbling with Swing to do some GUI stuff. This is relatively new
for me. At the moment I draw a rectangle for cropping an image. The
position is selected by clicking on the centre from where I think the
rectangle should be placed. This can be a little of, so I have to
fine-tune it. For this I draw a little cross in the centre. Problem is
that I paint it in black and when the centre is black, I will not see
it. And with every colour I choose I can have this problem. Is there a
smart way to make the cross always visible?

I was thinking about a timer function which would alternate the colour
of the cross between black and white, but was wondering if there is a
better way.

At the moment my code is:
    protected void paintComponent(Graphics g) {
        Graphics2D g2       = (Graphics2D) g;
        int        centerX  = x + cropWidth  / 2;
        int        centerY  = y + cropHeight / 2;

        super.paintComponent(g);
        g2.setStroke(stroke);
        g.setColor(rectColor);
        g.drawImage(image, 0, 0, imageWidth, imageHeight, null);
        g.drawRect(x, y, cropWidth, cropHeight);
        g.drawLine(centerX - crossLength, centerY, centerX + crossLength, centerY);
        g.drawLine(centerX, centerY - crossLength, centerX, centerY + crossLength);
    }

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Making a cross-hair visible Cecil Westerhof <Cecil@decebal.nl> - 2016-08-11 23:14 +0200
  Re: Making a cross-hair visible Arne Vajhøj <arne@vajhoej.dk> - 2016-08-11 17:34 -0400
  Re: Making a cross-hair visible Silvio <silvio@internet.com> - 2016-08-11 23:36 +0200
    Re: Making a cross-hair visible Cecil Westerhof <Cecil@decebal.nl> - 2016-08-12 00:20 +0200
  Re: Making a cross-hair visible Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-11 17:40 -0400

csiph-web