Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a rounded JFrame / ContentPane

Tags:

java

border

swing

I'm creating a login window with rounded corners in java. Everything is OK, see pic, but i'm having challenges making the JFrame / ContentPane transparent. There are white areas at each corner (shown by the arrows) that i seem not to be able to remove since i can't set opague to false for the JFrame or ContentPane.

Any ideas of how i can remove these white areas alt text

like image 790
n002213f Avatar asked Jun 05 '09 06:06

n002213f


1 Answers

Since Java 1.3 there's a trick which allows to make partially transparent windows, or windows fading in (I usually use this for my splash screens), or special FX (such as shadows):

  • Before opening the window, programmatically take a screenshot of the region where your window is going to be (using java.awt.Robot.createScreenCapture())
  • Set the screenshot as the background of your root container (JPanel with custom paintComponent() routine)
  • Now you can add all kinds of transparent components, or paint another semitransparent image on top of the background.

Example which creates a window with a semitransparent shadow using this technique: http://www.eclipsezone.com/eclipse/forums/t17720.html

like image 85
Peter Walser Avatar answered Oct 14 '22 17:10

Peter Walser