Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Component getComponent(String componentName) {
- return getComponent(componentName, this.frame.getContentPane());
- }
- private Component getComponent(String componentName, Component component) {
- Component found = null;
- if (component.getName() != null && component.getName().equals(componentName)) {
- found = component;
- } else {
- for (Component child : ((Container) component).getComponents()) {
- found = getComponent(componentName, child);
- if (found != null)
- break;
- }
- }
- return found;
- }
- JTextArea ta = new JTextArea();
- ta.setName("fooburg");
- JScrollPane scr = new JScrollPane(ta);
- frame.getContentPane().add(scr, "1, 1"); // EDIT: changed, tkx bruno
- void printNames(Component component) {
- System.out.println(component.getName());
- for (Component child : component.getComponents()) {
- printNames(child);
- }
- }
- void printFrameNamesComponents(JFrame frame) {
- printNames(frame.getContentPane());
- }
- frame.getContentPane().add(comp);
Add Comment
Please, Sign In to add comment