In our Swing application, we are using an automated testing tool in QA (Qf-Test) that works better when the swing components are named. (calling Component.setName). Although their automatic name assignments work reasonably well, we are introducing SwingX components into the project and that is causing some issues for the tool.
There are a lot of potential components on a screen (your typical business app data entry screens, but a lot of them - the app is on the complexity level of an ERP), what options are there for naming swing components in a reasonably unobtrusive manner?
I typically store the fields in a JPanel in properties on the JPanel, like this:
At the end of the routine that instantiates and lays out these components, you could run a routine that uses
java.lang.reflect
to loop through each property of the panel. If a property descends from the classComponent
, you can callsetName
on it with the name of the property. So for example, it would end up calling:...except through
java.lang.reflect
You could also have the routine examine the bumpy case names of variables and replace it with standard case with spaces. This would make them more readable.
This approach will ensure that no matter what components you add to a panel, they will all get friendly names.