Friday May 30, 2008

Reshaping NetBeans

Reading How to Create Translucent and Shaped Windows, I discovered a link at the end to a NetBeans project. That's pretty cool. And I've been using JDK 6 Update 10 Beta for quite a while now, so there was nothing special I needed to do to get set up. So I narrowed the code down to its absolute basics. I started by creating a new JFrame using the JFrame Form template in the IDE. Importantly, to create a round JFrame, you need to set its "undecorated" property to false (in Matisse GUI Builder that means just a click in a checkbox in the Properties sheet). Then define the main method like this:

public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        ComponentListener shapeListener = null;
        @Override
        public void run() {
            final JFrame frame = new NewJFrame();
            frame.addComponentListener(shapeListener = new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent evt) {
                    Shape shape = null;
                    shape = new Ellipse2D.Float(0, 0, frame.getWidth(), frame.getHeight());
                    AWTUtilities.setWindowShape(frame, shape);
                }
            });
            frame.setVisible(true);
        }
    });
}

Then run it and you have an ellipse instead of your boring old pointy cornered JFrame. Speaking of which, replace the line that defines the shape above with this one and you'll have a less radical result, i.e., not an ellipse, but a rounded rectangle:

shape = new RoundRectangle2D.Float(0, 0, frame.getWidth(), frame.getHeight(), 30, 30);

It's kind of funny when you're experimenting with this, because your JFrame is normal in design mode, while being transformed at deployment:

However, that's only the start. Since it is possible to grab the main window of the NetBeans Platform and cast it to a JFrame, you can do fun (though probably pointless) things like this:

The above is made possible via this Installer class in a NetBeans module which, when plugged into the NetBeans Platform, produces the results above:

public class Installer extends ModuleInstall {

    @Override
    public void restored() {
        SwingUtilities.invokeLater(new Runnable() {
            private ComponentListener shapeListener = null;
            public void run() {
                final JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
                frame.setUndecorated(true);
                frame.addComponentListener(shapeListener = new ComponentAdapter() {
                    @Override
                    public void componentShown(ComponentEvent evt) {
                        Shape shape = null;
                        shape = new Ellipse2D.Float(0, 0, frame.getWidth(), frame.getHeight());
                        AWTUtilities.setWindowShape(frame, shape);
                    }
                });
            }
        });
    }
}

An error is thrown because the "setUndecorated" is called at the wrong time. Not sure when to call it to fix this. Still, pretty cool to see the above results.

Other great articles on this topic are this one and this one by Kirill.

Updated: VisualVM Blog Entries and Other Documentation

Today I did something that I've never done before—I updated some of my blog entries. There had been several (well, one or two, to be exact) requests for me to update my VisualVM series to use the latest VisualVM APIs, and now I have done so. In each case you'll find that the blog entry begins and ends with the assurance that, despite the date on the blog entry being sometime in the past, the code is completely current, at least to the specified date.

Also, where applicable, I've referenced the new set of samples and templates that are helpful in getting started as well as troubleshooting the scenarios described in the blog entries. In fact, each of the scenarios discussed is now checked in as a sample on visualvm.dev.java.net and available in binary form as part of the VisualVM Sample Collection.

So, here's the list of blog entries on VisualVM, all of them updated to the current APIs:

In addition, the VisualVM API Quick Start has been completely updated. Next, I will work on the FAQs at the end of that document. Some need to be updated and there are other questions to be added to that document.

In other news. In the process of some tweaking, I messed up the CSS of this blog so that the left sidebar doesn't work as it should, i.e., the width is too wide. If some CSS guru could volunteer to help me unravel my CSS and fix that, I would really appreciate it. I'd also like the whole sidebar to be on the right side of the blog.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« May 2008 »
SunMonTueWedThuFriSat
    
2
5
7
16
20
22
25
28
       
Today