Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35258
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Making a cross-hair visible |
| Date | 2016-08-11 23:14 +0200 |
| Organization | Decebal Computing |
| Message-ID | <87a8gjm2it.fsf@Equus.decebal.nl> (permalink) |
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
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