How to count number of controls like JTextField, J Label and so on so..in java swing form designing,for example if we use only one textbox and one text field means i need the o
The container for the controls contains a list of controls, see Container.getComponents()
. Come to think, it also has a method for the count of the controls, if that's all you want, Container.getComponentCount().
If you want this for all the controls contained within containers contained (ultimately) in a frame, you will need to look at each one recursively; start with the frame, and for each component that is a container, get the controls/count in that container, etc. Keep in mind that panels can have panels.
rc
With SwingX, you have in class org.jdesktop.swingx.util.WindowUtils public static List<Component> getAllComponents(Container c)
. With that you have all components and subcomponents in container.
As they should all be inside your Container
object you can use the getComponentCount()
method to return you an int
of the number of components.
Container c;
int count;
count = c.getComponentCount();