How to name Java components inside docking frames ?


I’m working on a Java application where I need to test the docking behaviour, due to some rewriting of the docking frames behaviour.

To test this, I need to use qf-test. qf-test gives default names to Java Swing Components while testing, but these names can be differents every launch of the application, if their names are not set. If I can use components names, I’m sur to avoid problems when i run the tests.

How can I handle this with docking frames, for example, to name the panel containing the title, the panel containing the menu bar, or the buttons to dock or undock an element ?

Best regards,

Although it’s not entirely clear (for me) what the context of the question is, maybe mentioning @Beni will help.

Until then, I wonder whether you’re looking for something like this:

package bytewelt;

import java.awt.Component;
import java.awt.Container;

import javax.swing.JInternalFrame;

public class DeeplyAssignNames
    public static void main(String[] args)
        JInternalFrame f = new JInternalFrame("Title", true, true, true, true);
        deeplyAssignNames(f, "f");

    private static void deeplyAssignNames(Component component, String baseName)
        String name = component.getName();
        if (name == null)
            System.out.println("Assigning name: " + baseName);
            System.out.println("Component already has a name: " + name);
        if (component instanceof Container)
            Container container = (Container) component;
            for (int i = 0; i < container.getComponentCount(); i++)
                Component child = container.getComponent(i);
                String type = child.getClass().getSimpleName();
                    baseName + ".child_" + i + "_(" + type + ")");

It recursively walks through all components and assigns names (if they don’t already have one), but I’m not sure whether this is sensible (or „predictable enough“) to accomplish your goal… :confused:

In DockingFrames Components are created and thrown away all the time.

DockingFrames itself does not set, read or care about the names.

Personally I would try adding a DockControllerRepresentativeListener to the DockController, because all tabs and titles make themselves known as DockElementRepresentative - which gives access to the underlying Component. These should be enough methods on DockElementRepresentative to generate some useful name linked to its Dockable.

All the buttons (and menus) are going through the ActionViewConverter. You can use DockController.getActionViewConverter do gain access. Then use putClient to replace the creation of a button by your custom code that sets a name (just have a look at the code in ActionViewConverter to see how to setup one of the existing ViewGenerators).

Sorry, it’s a short answer. Let me know if you need more information.