Migration guide

Author: Dafe Simonek, Sun Microsystems/NetBeans
Abstract:
Window system migration guide for module owners, version 3.5 -> 3.6 Follow the instructions below to enable your module work smoothly with redesigned window system in Netbeans 3.6 release.
Document History:
$Revision: 1.1.1.1 $ available in CVS

Contents:

1. Border Policy

The goal of the border policy is to have clean and smooth borders without duplication, across the whole system. A common problem in Swing applications is "border buildup." Enforcing a border policy and some simple guidelines about how and when to use borders eliminates this problem and enables NetBeans to look modern and pleasant.
The next paragraphs will tell you what to do in your module's code.

1.1 No outer borders for TopComponent

If your module defines its own TopComponent, say YourTC extends TopComponent, ensure that it has no outer border. "Outer border" means outer in visual sense, usually attached to some inner subcomponent, not YourTC directly. The window system handles borders around TopComponents itself; internal borders will cause visually ugly duplication.

Here is an example constructor:

        YourTC () {
            ....
            JPanel content = new JPanel();
            setLayout(new BorderLayout());
            add(content, BorderLayout.CENTER);
        }
    
Example of bad design (duplicates borders around YourTC):
        YourTC () {
            ....
            JPanel content = new JPanel();
            content.setBorder(new EtchedBorder());
            setLayout(new BorderLayout());
            add(content, BorderLayout.CENTER);
        }
    

1.2 Remove JScrollPane's default border

We are again talking about TopComponents, now with scrollable content. JScrollPane has non-null border by default.You need to remove its default border to get clean borders.

Example of good YourTC with JScrollPane usage:

        YourTC () {
            ....
            JPanel content = new JPanel();
            JScrollPane scroll = new JScrollPane(content);
            // winsys handles outer borders itself, remove JScrollPane's border
            scroll.setBorder(null);
            setLayout(new BorderLayout());
            add(scroll, BorderLayout.CENTER);
        }
    
Example of bad design (duplicates borders around YourTC):
        YourTC () {
            ....
            JPanel content = new JPanel();
            JScrollPane scroll = new JScrollPane(content);
            setLayout(new BorderLayout());
            add(scroll, BorderLayout.CENTER);
        }
    

A note about JTable - If your component embeds a JTable in a JScrollPane, the method JTable.configureEnclosingScrollPane() will add a border to your scroll pane whether you want one there or not. This can be worked around either by using a JScrollPane subclass that makes setting the border a no-op, or subclassing JTable and overriding configureEnclosingScrollPane() to do everything it does by default except set the border.

1.3 Add border into explorer views in dialogs

BeanTreeView, ListView and TreeTableView have changed their border defaults. They now have no border by default, which is OK for their usage as TopComponents. In dialogs, it may be desirable to put ScrollPane's default border around them:
        YourDialogContent () {
            .....
            BeanTreeView btv = new BeanTreeView();
            btv.setBorder((Border)UIManager.get("Nb.ScrollPane.border")); // NOI18N
            add(btv);
            ....
        }
    
You can of course use regular Swing's borders, "Nb.ScrollPane.border" is a border provided by the core window system, designed to harmonize well with the rest of the window system. It will be different for different Look and Feels, as is the default Swing JScrollPane border.

Note that UIManager.get("Nb.ScrollPane.border") can return null in future, although it's unlikely. To be absolutely sure that your explorer view in a dialog will have some border, use a fall-back to some regular Swing border:

        YourDialogContent () {
            .....
            BeanTreeView btv = new BeanTreeView();
            Border btvBorder = (Border)UIManager.get("Nb.ScrollPane.border");// NOI18N
            // fallback if Netbeans.ScrollPane.border isn't available
            if (btvBorder == null) {
                btvBorder = new EtchedBorder();
            }
            btv.setBorder(btvBorder); 
            add(btv);
            ....
        }
    

Project Features

About this Project

core was started in November 2009, is owned by Antonin Nebuzelsky, and has 121 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close