473,728 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generate JTree with Data from XML files as input

50 New Member
Hi....

How to generate Tree with Data from XML as Input.

I use Netbeans and i tried generting a tree using DefaultMutableT ree node and inputs mentioned in same pane like,

DefaultMutableT reeNode classname1=new DefaultMutableT reeNode("CLASSN AME1");

But netbeans displays only the empty pane and no tree...

How to solve the two problems...

Thank you...
Mar 29 '09 #1
21 5786
JosAH
11,448 Recognized Expert MVP
Did you do something like the following in your JFrame?

Expand|Select|Wrap|Line Numbers
  1. this.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
  2.  
You do have to hookup your JTree to its parent component.

kind regards,

Jos
Mar 29 '09 #2
uhdam
50 New Member
Yes...

I had a panelname whose contents are dislayed in contentpane.

getContentPane( ).add(panelname );

scrollpane.getV iewport().add(t reename);

panelname.add(s crollpane,Borde rLayout.CENTER) ;

//scrollpane is name initialised for JScrollPane and
//panelname for JPanel
Mar 29 '09 #3
JosAH
11,448 Recognized Expert MVP
@uhdam
Try to do it this way:

Expand|Select|Wrap|Line Numbers
  1. scrollpane.setViewportView(treename);
  2.  
kind regards,

Jos
Mar 29 '09 #4
uhdam
50 New Member
HI..

Still i get only an empty frame as output. The tree is not displayed.
Mar 29 '09 #5
JosAH
11,448 Recognized Expert MVP
@uhdam
Show us a bit of relevant code: remove everything that is not directly relevant to the creation and display of your tree and produce a short, compilable example.

kind regards,

Jos
Mar 29 '09 #6
uhdam
50 New Member
package name;
import stmts;

public class Classname extends JFrame {

private JPanel topPanel;
private JTree tree1;
private JScrollPane scrollpane;

public Classname {
initComponents( );

setTitle(" Classes Trial ");
setSize(400,500 );
setBackground(C olor.gray);

topPanel = new JPanel();
topPanel.setLay out(new BorderLayout()) ;
getContentPane( ).add(topPanel) ;

DefaultMutableT reeNode className1 = new DefaultMutableT reeNode("TreeRo ot");

DefaultMutableT reeNode Methods1 = new DefaultMutableT reeNode("Method s1");
allMethods(Meth ods1);
className1.add( Methods1);

DefaultMutableT reeNode Attributes1 = new DefaultMutableT reeNode("Attrib utes1");
className1.add( Attributes1);

DefaultTreeMode l treeModel1=new DefaultTreeMode l(TreeRoot);
tree1=new JTree(treeModel 1);

scrollpane = new JScrollPane();
scrollpane.getV iewport().add(t ree1);
topPanel.add(sc rollpane1,Borde rLayout.BEFORE_ FIRST_LINE);

public void allMethods(Defa ultMutableTreeN ode mthd)
{
mthd.add(new DefaultMutableT reeNode("MD1")) ;
mthd.add(new DefaultMutableT reeNode("MD2")) ;
mthd.add(new DefaultMutableT reeNode("MD3")) ;
}

public static void main(String args[]) {
java.awt.EventQ ueue.invokeLate r(new Runnable() {
public void run() {
new Classname().set Visible(true);
}
});
}
Mar 29 '09 #7
JosAH
11,448 Recognized Expert MVP
Your example doesn't compile: what is TreeRoot?

kind regards,

Jos
Mar 29 '09 #8
uhdam
50 New Member
its classname.tree rootnode.

Replace classname with ClassDisp and TreeRoot with Classname1;

sorry for the inconvenience..

Thankyou
Mar 29 '09 #9
uhdam
50 New Member
i worked in netbeans.. it generates some code automatically.. .

the initcomponents will be that way na..


/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="c ollapsed" desc=" Generated Code ">//GEN-BEGIN:initCompo nents
private void initComponents( ) {

setDefaultClose Operation(javax .swing.WindowCo nstants.EXIT_ON _CLOSE);
javax.swing.Gro upLayout layout = new javax.swing.Gro upLayout(getCon tentPane());
getContentPane( ).setLayout(lay out);
layout.setHoriz ontalGroup(
layout.createPa rallelGroup(jav ax.swing.GroupL ayout.Alignment .LEADING)
.addGap(0, 400, Short.MAX_VALUE )
);
layout.setVerti calGroup(
layout.createPa rallelGroup(jav ax.swing.GroupL ayout.Alignment .LEADING)
.addGap(0, 300, Short.MAX_VALUE )
);
pack();
}// </editor-fold>//GEN-END:initCompone nts


should you include initcomponents code which is generated by the netbeans itself.
Mar 29 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4168
by: Mitch Williams | last post by:
I've been working with a JTree based on a custom TreeModel. Unfortunatly, I cant figure out how to force it to update the entire tree-- there simply dosnt seem to be a way to say "OK, your data changed so drastically, it's not even worth me telling you where to start". I have tried the fireTreeStructureChanged event, but that only updates the tree structure, leaving nodes that have changed only by name unchanged and me cursing. I've also...
2
11122
by: Piet | last post by:
Hi there, I have managed to write a small java program that display an xml file in a JTree. This was achieved by defining a suitable tree model. THe program works...somehow. The nodes (elements and texts) are correctly recognized, and the corresponding branches in the JTree can be opened and closed. However, when I run the program, all the non-leaf nodes (e. g. the element nodes) are displayed from the start tag to the end tag including...
0
1689
by: Lucia | last post by:
hello, I habe a Java Program that displays the XML document in a Java JTree using DOM. Now I can add, delete and edit the JTree Elements. But I don't know how to show the attributes also in the JTree and how to edit them. Do you have any advice? Thanks
0
2257
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional assistance. I say additional because I've already had help which is greatly appreciated. I do try to take the time and understand the provided script in hopes on not having to trouble others on those. But here it goes...
0
2399
by: luvping04 | last post by:
Hey, i told to make a java program to load xml into JTREE using SAX api. i'm suppose to load the 1st layer of the jtree and hide the subtree into memory. How can i load the subtree into memory? i was told this way will speed up the loading of largest dataset. pls provide me with some guidance best regards
0
1115
by: flavourofbru | last post by:
Hi, I am converting a given html document into a tree structure and displaying it using JTree and DefaultMutable classes. By using the html parser and the JTree functionality, I can display the html doc as tree structure, but now I would like to get the subtrees only of that tree when clicked on any of the nodes in the tree or else If I input the node, I need to display only the subtree associated with that node and not the entire tree. Is...
2
1299
by: msali36 | last post by:
Hi, i just want to know how can i display the parent- child information in hirarchy tree format in vb.net. for example : GrantParent parent parent
2
1721
by: ace84 | last post by:
Hi, I am creating an application where I want to show a file system. I have never worked with them before, so i am not sure on what I need to do to accomplish my goal. So far I found a script through google that lists all the files and folders. What I want to do is modified the script to only show just the folders, then when the user clicks on the folder, I want to populate another object (maybe JList), with only images(jpg,bmp,tiff,png,gif)...
1
3965
by: sivakrish85 | last post by:
Hi, this is krishna i am on developing FTP in java.Here i display the server Files and client Files in tree view using JTree.So my question is that once the client send the file to server (or) server send the file to client.The new file(or) folder should be added as a node in Jtree.After clicking refresh option in pop up.The tree is not get
0
8758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9422
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8129
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6716
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4792
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2663
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.