How to display html as a tree in Swing? - java

I would like to display html as treeview similar to firebug in my swing. Looking for community help to achieve this. Found similar stuff(Not Exactly) here. But i could not move further with the information in the link.

In general, you need a HTML DOM parser (like JSoup) to create a DOM tree from the HTML code you have. Then you should probably build your own TreeModel to respresent the DOM tree in a swing JTree.

This tutorial will tell you exactly how to create a JTree that shows the DOM structure of an HTML document.

You can use this http://java-sl.com/JEditorPaneStructureTool.html to see how it could be implemented.
After reading HTML with HTMLEditorKit use the HTMLDocument's tree.

Related

Screen scraping, extract text data from DOM tree

I'm trying to scrape specific text from a website using jsoup. The text doesn't appear to be in the html that I'm downloading, but rather in the DOM tree. Im not exactly sure how this works because I'm new at it. When I view the source of the website I'm unable to see or find the text that I'm looking for, but I can find it in the DOM tree. How can I extract the data?

Custom Java Swing XML Editor

I need to show an xml as a tree structure in a java swing application. When I click on any node in the swing tree its attribute should list in a window (like a properties editor) and from that I need to update the attributes. Also I need to hide some nodes in the xml in the tree.
I am planning to use JTree to populate and show the xml as tree. But bit confused about what approach need to take to read/update the xml.
Currently I have the below options:
Using JAXB create the corresponding objects and populate the JTree
Use any parser DOM or SAX and populate the JTree using the DefaultMutableTreeNode
Please advice what approach I need to proceed? or is there any other better way for doing this?

Expandable list in pdf files

Can i create an expandable list in pdf files. Expandable list will be of the form :
+Item1
+Item2
-Item3
-Subitem3.1
-Subitem3.2
+Item4
-Item5
-Subitem5.1
-Subitem5.2
-Subitem5.3
Also I need to create the pdf file from Java(I was thinking of using iText, is another library better/easier?). Is this possible. Or is a report in some other standard format(not pdf or html) an easier way out.
First this: I'm the creator of iText, so forgive me for not pointing you to other solutions ;-)
Now for your question: you're asking for dynamic functionality (a tree structure that opens/closes upon user interaction) inside a PDF document.
The most obvious answer is: this isn't possible. When creating PDF, think of paper. Can you print a tree structure on paper that opens/closes when the end user touches the paper? No, you can't, therefore you're asking something that isn't possible in PDF.
The less obvious answer is: it depends. What type of PDF are we talking about?
If you're talking about an interactive XFA form, then you may be able to achieve what you want. The XML Forms Architecture (XFA) is an XML specification that can be used to define interactive forms. When you use XFA, the PDF is nothing more than a container for XML. This XML is rendered dynamically inside Adobe Reader. How to create an XFA form? I only know about two products: Adobe LiveCycle Designer and Avoka Smart Forms Designer.
If you're talking about 'regular PDF', then one option is to embed a swf file. In this case, the tree structure will be rendered by Flash player (which could be a disadvantage, because this might not work with all PDF viewers). Another disadvantage: the tree structure will be confined to a fixed rectangle on a fixed page.
Finally: you can have create such a structure in the bookmarks panel. In PDF terminology, those bookmarks are called Outlines. Obviously, the tree structure won't be a part of the printable content. It will be visible in a separate panel in your PDF viewer.

creating java help using single HTML file

I have one HTML file which contains 200 definitions and i don't want to create 200 HTML files. I want to create java help using that file such that if user click on TOC(table of content) list and user can reached at the particular definition without scrolling that html documentation.
First study how to make tree like structure using JTree and then study how to show html page in Jframe using JEditorPane.

View GWT HTML source?

Is there a way to VIEW the HTML source code that GWT produces? Currently I just give my flex table the DIV id and that DIV is all HTML I can see in ViewSource.
Is there a way to structure my table in HTML (say using div's and lists) and than create a something like FlexTable around that?
To answer the original question, you can view the HTML GWT has rendered via 'Inspect Element' in Firefox, with Firebug is installed. Alternatively the Web Inspector in Safari/Chrome will do the trick, as will the Developer tools in both IE8 and Opera.
Well well it seems the answer is in the documentation.
In particular Organizing Projects outlines how we can bind different widgets to different id's on the page.
So I can effectively do something like:
# html
<div id="id_table"></div>
<div id="id_next_button"></div>
# java
t = new FlexTable()
RootPanel.get("id_table").add(t);
nextbtn = new Button("next");
RootPanel.get("id_next_button").add(nextbtn);
Wohoo!
Regarding the second part of your quetion. It is possible to create a HTML component in GWT. The recomended way to do this is extending ComplexPanel and create the elements using Document.get().createXXXElement(). But it is a little laborius.
Check out this dicussion and I am sure there are other articles about this around the internet. You can also study the code of other components the extend ComplexPanel.

Categories