简体   繁体   中英

Create form with round corners

I'm using NetBeans, and I have a blank JFrame . The JFrame is literally empty. I want this JFrame to have round corners.

How can I do that?

if you want rounded corners, then you want a shaped frame. You can achieve that by calling Frame.setShape . Quoting from its documentation:

The following conditions must be met to set a non-null shape:

The second of these points, an undecorated frame, corresponds to a part of your original question which was rephrased in a subsequent edit: It will give you

No windows like stuff, just the form, with no exit button, nothing.

try this. its work :)

yourframe.setBackground(new Color(0, 0, 0, 180));
yourframe.setUndecorated(true);
yourframe.addComponentListener(new ComponentAdapter() {
               @Override
                public void componentResized(ComponentEvent e) {
                    setShape(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 80, 80));
                }
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM