salut
J" utilise ce code pour afficher les données de mon annuaire LDAP comme un arbre
JTree jtree ;

private DirContext dirContext = null;
DefaultMutableTreeNode root;
private String filter = "(ObjectClass=*)";
private Hashtable existNodes = new Hashtable();
JPanel panel;
JScrollPane scrollPane;


public TestScroller( String base) {

panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder());

panel.setPreferredSize(new Dimension(415,420));

scrollPane = new JScrollPane(panel);
scrollPane.setPreferredSize(new Dimension(200,295));
JTree jtree = buildTree(base);

scrollPane.setViewportView(jtree);

add(scrollPane);



}

public void getConnection() {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:11389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system"); // specify the username
env.put(Context.SECURITY_CREDENTIALS, "secret");

dirContext = new InitialDirContext(env);
} catch (Exception ex) {
ex.printStackTrace();
}
}




public ArrayList getDN(String base) {
ArrayList list = new ArrayList();
try {
getConnection();
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration results = dirContext.search(base, filter, constraints);
while (results != null && results.hasMore()) {

SearchResult si = (SearchResult) results.next();
list.add(si.getNameInNamespace());
System.out.println(list);

}
} catch (NamingException ex) {


}
return list;
}


private String getCreatedDn(String[] str, int i, int j) {
if (i < 0 | i > str.length | j > str.length | j < 0 | i > j) {
return null;
}
String ret = str[i];
int k = i + 1;
while (k < j - 1) {
ret += "," + str[k];
k++;
}
return ret;
}




public JTree buildTree( String base) {
jtree = null;
ArrayList dnList = getDN(base);
Iterator it = dnList.iterator();
root = new DefaultMutableTreeNode(base);
int baseLenth = base.split(",").length + 1;
System.out.println(baseLenth);
while (it.hasNext()) {
String dnStr = (String) it.next();
String[] nodes = dnStr.split(",");
int j = nodes.length;
int k = j - baseLenth;

DefaultMutableTreeNode a = root;
for (int i = k; i >= 0; i--) {
String nodeDN = getCreatedDn(nodes, i, k);
if (existNodes.containsKey(new String(nodeDN))) {
a = (DefaultMutableTreeNode) existNodes.get(new String(nodeDN));
continue;
}
DefaultMutableTreeNode b = new DefaultMutableTreeNode(nodes[i]);
existNodes.put(new String(nodeDN), b);
a.add(b);
a = b;
}
a = null;
}
existNodes = null;
jtree = new JTree(root);

return jtree;
}
public static void main( String args[] )
{
String base="";

JPanel baseView = new TestScroller(base);
baseView.setPreferredSize(new Dimension(5,5));
baseView.setOpaque(false);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(baseView);
frame.setSize(500,500);
frame.setVisible(true);
frame.repaint();
}



}



en compilant j'ai eu cette arborescence
Nom : Capture.JPG
Affichages : 95
Taille : 25,0 Ko
je veux l'afficher comme ça
Nom : 2.JPG
Affichages : 84
Taille : 14,4 Ko