Java GUI: Document Object Model
HTML has a document object model, and then JavaScript can manipulate / move
When I create a GUI in swing - the model looks very different (I don't know the name of the model) because I'm creating a layout manager and pasting objects in it
My question: is there any way to manipulate Java GUIs in a DOM like manner?
[for example, I want to be able to delete / add nodes, move children, etc...]
thank you!
Solution
For swing components, everything starts with a set of jframes (you can also have jwindow and jdialog, but you usually have at least one root frame) Most likely, all you care about is the content pane of the JFrame (but you can also care about the windows it has, etc.)
Therefore, from JFrame, you can get the content pane as follows:
Container contentPane = frame.getContentPane();
From there, you can start using the following component tree:
Component[] children = contentPane.getComponents();
From the child, you can get its parents:
Container parent = child.getParent();
To add a component to a container:
container.add(someComponent); container.validate();
To remove a component from a container:
container.remove(someComponent); container.validate();
To move a component from one container to another, simply remove it from one container and add it to another
I'm not sure this will answer your question It will be easier if you can post real examples of what you want to do