a netbeans rcp blog

Wallpaper in a NetBeans RCP application

Posted by Nicklas Löf on February 18, 2011

Yesterday I wrote about my attempts to put an image in the root window of a Netbeans RCP application that is shown when no TopComponents are open.

Today I did finalize the code and added so I could add a logotype at the bottom on the right side and when the application window is resized it will stay at the bottom right side. So here is the complete code.

    private ImageIcon bgimage;

    public void restored() {
        bgimage = new ImageIcon(ImageUtilities.loadImage("path/to/my/wallpaper.jpg"));
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    JFrame main = (JFrame) WindowManager.getDefault().getMainWindow();
                    JPanel mainPanel = new JPanel(new BorderLayout()) {

                        public void add(Component comp, Object constraints) {
                            super.add(comp, constraints);
                            if (constraints == BorderLayout.CENTER) {
                                if (comp instanceof JPanel) {
                                    final JPanel panel = (JPanel) comp;
                                    panel.add(new BackgroundLabel(bgimage), java.awt.BorderLayout.CENTER);

    private class BackgroundLabel extends JLabel {
        private boolean showBgImage = true;
        private ComponentAdapter componentAdapter;
        private Image image;

        public BackgroundLabel(ImageIcon imageIcon) {
            image = ((ImageIcon) getIcon()).getImage();
            TopComponent.getRegistry().addPropertyChangeListener(new PropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent evt) {
                    if (TopComponent.getRegistry().getOpened().isEmpty()) {
                        showBgImage = true;
                    } else {
                        showBgImage = false;

        public void paintComponent(Graphics g) {
            if (showBgImage) {
                int x = getParent().getSize().width - image.getWidth(this);
                int y = getParent().getSize().height - image.getHeight(this);
                g.drawImage(image, x, y, image.getWidth(this), image.getHeight(this), this);

        private void setupAdapter() {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    componentAdapter = new ComponentAdapter() {

                        public void componentResized(ComponentEvent e) {

Any image loaded into bgimage will be put at the bottom right corner of the application and stay there even when the window resizes.

To modify this behaviour just change the x and y parameters in paintComponent(Graphics g). For example setting them to 0,0 would draw the image at the top left corner. To stretch an image the width and height parameters should be modified.

Here is two screenshots showing this in action. The first one is just a quick logo I did created in GIMP since I can’t show my real application here, the other one is a fullscreen netbeans desktop background downloaded from


5 Responses to “Wallpaper in a NetBeans RCP application”

  1. […] (RSS) « Place the quicksearch component anywhere you like Wallpaper in a NetBeans RCP application […]

  2. Geertjan said

    Interesting and cool. It kind of relates to this:



  3. ramblingbyte said


    Thanks for the awesome tutorial. I tried to do exact the same thing you describe but I couldn’t make it work. I created a independent module, defined a module installer and a BackgroundLabel class, but nothing happens when I fire up the application and to be honest I have no idea what I’m doing wrong. I’m pretty new to NetBeans RCP so any hint how to make it work will be greatly appreciated. I will check back in case you answer to reply. Thanks again. 🙂

  4. Rafa said

    And, where put all this code?

  5. Cora said

    Many who were unable to obtain financing from any other
    source have successfully bootstrapped their way to business success.
    If you’re thinking of making an offer on a property without an actual rent
    roll or financials – see if you can get the “average” rent per unit and
    number of units. We would venture to say that the overall cost
    of production varies greatly in Canada depending on which province is utilized,
    via labour and other geographical incentives.
    Using additional collateral can be an important
    element in the financing process of a semi-truck.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: