Java GUI: Document Object Model

前端 未结 2 1292
隐瞒了意图╮
隐瞒了意图╮ 2021-01-05 05:54

HTML has a Document Object Model, which Javascript can then manipulate / move around.

When I create GUIs in Swing -- the model appears to be very difference (I don\'

相关标签:
2条回答
  • 2021-01-05 06:14

    For Swing components, everything starts from a set of JFrame's (you can also have JWindow's and JDialog's, but you usually have at least one root frame). Most likely, all you care about is the contentPane of that JFrame (but you could care also about its ownedWindows, etc...).

    So from the JFrame, you can get the content pane as following:

    Container contentPane = frame.getContentPane();
    

    From there, you can start going down the Tree of components, using:

    Component[] children = contentPane.getComponents();
    

    From a child, you can get its parent with:

    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 and add it to the other.

    I am not sure this answers your question. It would be easier if you could post real examples of what you are trying to do.

    0 讨论(0)
  • 2021-01-05 06:22

    I'm not sure this addresses your concerns but there are XML-driven Java UI toolkits.

    0 讨论(0)
提交回复
热议问题