Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: Making a cross-hair visible Date: Fri, 12 Aug 2016 00:20:15 +0200 Organization: Decebal Computing Lines: 57 Message-ID: <871t1vlzhc.fsf@Equus.decebal.nl> References: <87a8gjm2it.fsf@Equus.decebal.nl> <57aceffb$0$4222$e4fe514c@newszilla.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="10668"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Og9Ls5WXktoe1PjOfM02DwumKqUiPOo4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:pG/kyMpvueYwK53E/gG4xt+B38g= sha1:s9R8U+5h9qKcDWszX8r3HtoYExI= Xref: csiph.com comp.lang.java.programmer:35265 On Thursday 11 Aug 2016 23:36 CEST, silvio@internet.com wrote: > On 08/11/2016 11:14 PM, Cecil Westerhof wrote: >> 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); } >> > > Either do a black crosshair with a white border or draw in XOR-mode. Why did I do not think about that. :'-( I had already been experimenting and I got a good result with: new Color(0, 255, 0) as the cross colour. But that this colour is not significantly used in my pictures, does not mean it is the same in others. I changed the last part to (it has to be cleaned up of-course): g2.setStroke(new BasicStroke(4.0f)); g.setColor(new Color(255, 255, 255)); g.drawLine(centerX - crossLength, centerY, centerX + crossLength, centerY); g.drawLine(centerX, centerY - crossLength, centerX, centerY + crossLength); g2.setStroke(new BasicStroke(2.0f)); g.setColor(new Color(0, 0, 0)); g.drawLine(centerX - crossLength, centerY, centerX + crossLength, centerY); g.drawLine(centerX, centerY - crossLength, centerX, centerY + crossLength); And that works great on the blackbird where I did not see the cross earlier on. Maybe I should do the same for the rectangle itself. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof