1

Hello Im working with jframe (in java) and I wonder if there is some sort of list for all the jframe Components.

What I mean with Components: jbutton, jtextarea, jcombobox and stuff like that

1

1 Answer 1

1

You can use JFrame#getComponents that is inherited from Container

Gets all the components in this container.

Note: This method should be called under AWT tree lock. Returns: an array of all the components in this container. See also: Component.getTreeLock()

Example

Component[] frameCompos = myFrame.getComponents();
// How to print it?
// 1
for (Component c : frameCompos) {
    System.out.println(c);
}
// 2
System.out.println(Arrays.toString(frameCompos));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer, how do I display it? System.out.println(frameCompos) just prints: [Ljava.awt.Component;@52d455b8
@MCrafterzz Edited it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.