> Hi, > > 1. I don't understand why Java 2D classes such as > Rectangle2D have float and double constructors, and > not integer constructors? I thought these values > represented pixel coordinates? Are these values > rounded, or what? (I know I'm missing something huge > here, so this is an embarrassing question to ask) >
You can pass int parameters to either of the Float or Double constructors, or you could use the legacy java.awt.Rectangle class, which operates on int parameters only. As for your second question, Java 2D is a vector graphics library, and as such there isn't necessarily a one-to-one mapping between coordinates (integer or otherwise) and pixel locations on screen. For example, you could have an ellipse positioned at (1.345, 2.2), which could be rendered slightly differently than one rounded down to (1, 2), especially when you're talking about antialiased rendering, or if you're printing, or... > 2. Should methods in the Graphics class, such as > drawRect, ever be used? (i.e., should you always cast > the Graphics object to Graphics2D, and call > draw(myShape2D)?) > The drawRect(), fillRect(), etc methods on the Graphics class are still your best bet, especially if you're concerned with performance. It's the principle of "tell us exactly what you mean". If you want to fill a rectangle, it's much better to use fillRect() as we can use our fast/dedicated filling code under the hood. If you use fill(Rectangle2D), we'll jump through all kinds of hoops to end up with the same visual results. > 3. What is the best way of filling a rounded > rectangle with 2 gradients, as shown here: > http://ld.hostrocket.com/images/rr_grad.png > > I believe the LinearGradientPaint in Mustang will > make this a lot easier, but I'd like it to at least > run on Tiger (I think). > > What I did was set the clip to a rounded rectangle, > and then fill two separate rectangles using a > GradientPaint. I then 'reset' the clip, and drew the > rounded rectangle border. (The corners of the border > seemed to be cut off if I didn't remove the clip -- I > probably did something wrong) Anyway, is this an > acceptable solution? Is there a better way to do it? > On Tiger, you pretty much have no choice but to use the two-pass technique you describe (clip, fillRR, clip, fillRR, reset clip, drawRR). The behavior you're seeing where the corners are clipped off is caused by slight differences between the clip region and the way the rounded rect shape is stroked, so if you don't need the clip set, the resetting the clip to its previous value is not a bad idea (as you've found). On Mustang, you can do the fill in one pass using LinearGradientPaint and CycleMethod.REPEAT, where the repeat boundary is in the middle of your button (such that you get a hard boundary between the first and last colors, as in your screenshot). > Any other Java 2D tips are welcome. :) > 1. Don't use drawRoundRect() to draw one-pixel tall horizontal lines. 2. See #1. :) Thanks, Chris [Message sent by forum member 'campbell' (campbell)] http://forums.java.net/jive/thread.jspa?messageID=115538 =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
