Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

Giving 2d shapes a raised appearance

Thread view: 
Gyruss - 09 May 2005 13:32 GMT
Hi,

Is there a simple means of giving a java.awt.Rectangle a raised or 3D
appearance?

Cheers!
Thomas Weidenfeller - 09 May 2005 14:25 GMT
> Is there a simple means of giving a java.awt.Rectangle a raised or 3D
> appearance?

If you can live with a sometimes cheap looking shadow effect, then draw
two rectangles of the same size, but with a slight x and y offset (e.g.
5, 5 pixels offset) of the the origin. E.g. give both rectangles a black
border, but fill the first (lower) rectangle with black, and fill the
second (upper) rectangle with white.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

FaeLLe - 09 May 2005 14:27 GMT
Beveled border

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/BorderFactory.html
John McGrath - 09 May 2005 14:45 GMT
> Is there a simple means of giving a java.awt.Rectangle a raised or 3D
> appearance?

Have you tried giving it a RaisedBevelBorder?

Signature

Regards,

John McGrath

Thomas Weidenfeller - 09 May 2005 16:17 GMT
> Have you tried giving it a RaisedBevelBorder?

Borders are intended for Component decoration. Rectangle, however, is
basically a Shape. You can abuse most Border implementations and
convince them to paint on an arbitrary location on some JPanel's
Graphics2D context. You have to provide some fake Component. However,
this usually only works, because the Border implementations don't
interact much with the Component. But this is an implementation details,
and Sun might at any point in time decide to do things differently.

Therefore I wouldn't use a Border. Instead I would paint the two to
three lines per side myself.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

John McGrath - 09 May 2005 19:26 GMT
> > Have you tried giving it a RaisedBevelBorder?
>
> Borders are intended for Component decoration. Rectangle, however, is
> basically a Shape.

Yes, I did not read the question carefully and I was thinking he was
talking about a component, not a Shape.

Still, I would recommend looking at a raised BevelBorder and other Border
classes to find one that provides the desired effect, and then look at the
source code to see how to implement the effect.

Signature

Regards,

John McGrath

Remi Bastide - 10 May 2005 08:02 GMT
>> Have you tried giving it a RaisedBevelBorder?
>
[quoted text clipped - 10 lines]
>
>/Thomas

What about graphics.fill3DRect(...) ?
John McGrath - 11 May 2005 15:45 GMT
> What about graphics.fill3DRect(...) ?

That works, but not very well, IMO.  The Graphics context only contains
a single color, so the draw/fill 3D operations need to derive multiple
colors from the current color using operations like the Color darker()
and brighter() methods.  I find it works much better if you choose the
colors yourself and draw the individual lines.

Signature

Regards,

John McGrath



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.