0% found this document useful (0 votes)
119 views2 pages

Htmltree Code Aguason

The document defines a class called HtmlTree that creates a JTree to display an HTML document structure. It builds the tree by creating DefaultMutableTreeNode objects for each HTML element and adding them to the tree in the proper hierarchical order.

Uploaded by

Justine Aguason
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views2 pages

Htmltree Code Aguason

The document defines a class called HtmlTree that creates a JTree to display an HTML document structure. It builds the tree by creating DefaultMutableTreeNode objects for each HTML element and adding them to the tree in the proper hierarchical order.

Uploaded by

Justine Aguason
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package htmltree;

import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;

public class HtmlTree


{
public static void main(String... ar)
{
SwingUtilities.invokeLater(() -> {
html a = new html();
});

}
}

class html
{
JFrame jf;
JTree tree1;
DefaultTreeModel HTree;

html()
{

jf= new JFrame("JTree Example_Aguason");

DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("html");

DefaultMutableTreeNode head = new DefaultMutableTreeNode("head");


DefaultMutableTreeNode body = new DefaultMutableTreeNode("body");
DefaultMutableTreeNode h2 = new DefaultMutableTreeNode("h2");

DefaultMutableTreeNode ul = new DefaultMutableTreeNode("ul");

rootNode.add(head);
rootNode.add(body);
body.add(ul);
body.add(h2);

DefaultMutableTreeNode head1 = new DefaultMutableTreeNode("meta");


DefaultMutableTreeNode head2= new DefaultMutableTreeNode("title");

head.add(head1);
head.add(head2);

DefaultMutableTreeNode li = new DefaultMutableTreeNode("li");


DefaultMutableTreeNode li2= new DefaultMutableTreeNode("li");

DefaultMutableTreeNode h1 = new DefaultMutableTreeNode("h1");

ul.add(li);
ul.add(li2);
body.add(h1);
body.add(h2);

DefaultMutableTreeNode a = new DefaultMutableTreeNode("a");


h2.add(a);

HTree= new DefaultTreeModel(rootNode);

JTree tree = new JTree(HTree);

JScrollPane scrollP = new JScrollPane(tree);

scrollP.setBorder(BorderFactory.createEmptyBorder());
scrollP.setPreferredSize(new Dimension(300, 230));

jf.add(scrollP);

jf.setLayout(new FlowLayout());
jf.setSize(400,320);
jf.setVisible(true);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy