Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Java Swing JFrame with a circular shape?

Tags:

java

swing

jframe

How to make a circular JFrame if possible?

like image 667
Ahmed Ibrahem Avatar asked Mar 01 '11 13:03

Ahmed Ibrahem


People also ask

How do I add a circle to a JFrame?

You can draw a circle and oval using the Graphics. drawOval(int x, int y, int width, int height) method. This function performs both functions. 'x' and 'y' are the starting point on the screen, and 'width' and 'height' are the parameters to set the width and height of the oval or circle.

How do you change the shape of a JFrame?

Essentially what you have to do is make the outer part of your JFrame rendered surface transparent and then draw your own custom shape in the middle.

How do you make a circle in GUI?

Circle is just suppose to draw a circle in the frame created by Frame with random starting position (and defind the radius). Frame is the mainclass with methods such as addCircle(), bounce(), start(), stop(), run() (moves the circles) and quit(). This class also creates the frame in which the circles are added to.

What is difference between JFrame and JPanel?

Basically, a JFrame represents a framed window and a JPanel represents some area in which controls (e.g., buttons, checkboxes, and textfields) and visuals (e.g., figures, pictures, and even text) can appear.


1 Answers

Oracle has a nice tutorial on exactly this topic: https://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html

Shaped Windows

The other feature introduced in release 6u10 is the window shaping effect. Using shaping you can set any shape to an undecorated window. When the effect is applied, the desired area of a window becomes transparent. Thus, the combination of transparent and non-transparent pixels form the shape of a given window. The next images demonstrate window shaping in two cases:

[Text extracted from original article http://www.oracle.com/technetwork/articles/javase/translucent-shaped-windows-139324.html ]

like image 77
jzd Avatar answered Sep 29 '22 11:09

jzd