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 / January 2005

Tip: Looking for answers? Try searching our database.

Semi-transparent JTextField?

Thread view: 
Allysia - 21 Jan 2005 21:45 GMT
Is there any easy way to make a JTextField semi-transparent (maybe 50%
alpha)?

I tried setting the background color to "new Color(255,255,255,70)", but
the JTextField's background pickedup all sorts of weird things, and became
less transparent with each keystroke.

Do I have to create an extension of JTextField and overload the paint()
function?

-Ally
Steve W. Jackson - 21 Jan 2005 22:13 GMT
>:Is there any easy way to make a JTextField semi-transparent (maybe 50%
>:alpha)?
[quoted text clipped - 7 lines]
>:
>:-Ally

That's method, not function -- let's be OO purists.  :-)

Actually, you should not generally override paint() in a Swing
component.  You might be interested in a good page on the topic at
<http://java.sun.com/products/jfc/tsc/articles/painting/index.html>.  In
fact, it might even offer clues to the actual source of your trouble.

Without detailed code samples and other things, I can't do much more
than speculate, but it may be that opacity is involved in this as well.  
Once you read that article, you'll understand what paint() actually does
in Swing -- which is to paint the component itself, then its border,
then its children.  Swing components, as subclasses of JComponent, all
have the setOpaque(boolean) method.  This lets you create a contract
between the RepaintManager and your Swing component indicating whether
or not you'll draw the entire background when painted.  Judicious use of
this call, and a good understanding of what happens when it's true or
false, could help to get you where you want to be.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Andrey Kuznetsov - 22 Jan 2005 02:25 GMT
>>:I tried setting the background color to "new Color(255,255,255,70)", but
>>:the JTextField's background pickedup all sorts of weird things, and
[quoted text clipped - 23 lines]
> this call, and a good understanding of what happens when it's true or
> false, could help to get you where you want to be.

You should also be aware, that caret of JTextField is repainted
with paintImmediately(x, y, w, h) what could lead you
to additional problems.

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities



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.