Minha JTree não aparece

Salve galera, tou postando meu primeiro tópico aqui no GUJ, estou com uma dúvida cruel já a uma semana e não consigo resolver.

Antes de tudo: sou iniciante, perdoem-me portanto os erros grotescos! :smiley:

Pois bem, no projeto em que eu sou bolsista, meu professor me deu uma aplicação lá e pediu pra na interface colocar uma parte (como um panel) que tivesse uma arvore de diretorios, e que clicando neles, em um panel de baixo aparecesse os arquivos daquele diretorio. Pesquisando muito na net, e pegando alguns tutoriais consegui fazer alguma coisa. Porém estou parado há dois dias em uma parte que não consigo resolver, que é fazer aparecer minha arvore no Panel! O pior é que fiz exemplos, fiz um exemplo pessoal, criando a arvore e tal, e aparece tudo bunitim, mas na aplicação que o professor mandou a bendita arvore nao aparece.

O que eu decidi fazer foi refazer toda a classe que o professor me deu, reorganizando ela toda pois estava cheio de coisa sem necessidade, porém, mesmo assim, não tá aparecendo e tenho certeza que é alguma coisa besta que não tou conseguinto perceber. Espero que vocês possam me ajudar, eu saindo desse impasse consigo continuar, e com certeza terei mais dúvidas.

Outra coisinha, meu professor pediu pra eu resolver outro problema também que tb acho que é uma questão besta: Toda vez que rodo a interface, todos os componentes lá contidos não aparecem a não ser que eu minimize e depois restaure a janela, o que é isso? Algumas vezes é que presta.

Abaixo segue o código:

[code]package org.arena.water.beer.guis.hydroelements;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.border.EtchedBorder;
import javax.swing.tree.DefaultMutableTreeNode;

import org.arena.water.beer.BEER;
import org.arena.water.beer.guis.ExtensionFileFilter;
import org.arena.water.beer.hydroelements.ACM_Gauge;

public class GUIRainFallGaugesTest extends JFrame {

private static final long serialVersionUID = 1L;

private JTree tree;

private JPanel panelButtons;
private JPanel panelTree;

private JButton btnImportExportArray10;
private JButton btnImportExportArray20;
private JButton btnExportData;
private JButton btnChart;
private JButton btnClose;
private JButton btnOneGauge;
private JButton btnAllGauges;

private JFileChooser chooser;

private JTable tblRainfallGaugesData;

private ArrayList<ACM_Gauge> gauges;

private BEER beer;

public GUIRainFallGaugesTest(BEER beer){
	super("Rainfall Gauges");
	
	this.setBounds(100, 200, 530, 370);
	this.setPreferredSize(new Dimension(530, 370));
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	this.setResizable(false);
	this.setVisible(true);
	this.pack(); 
	
	panelButtons = formatPanelButtons();
	panelTree = formatPanelTree();

	this.add(panelTree);
	this.add(panelButtons);
	
	if (beer != null){
		this.beer = beer;
		if (this.beer.getWatershed().getRainfallGauges().size() != 0)
			this.gauges = beer.getWatershed().getRainfallGauges();			
	}
	
	if (this.gauges != null){
		this.insertDataIntoTable();
	}

	this.createFileChooser();
}

private void createFileChooser() {
	this.chooser = new JFileChooser(new File("."));
	
	ExtensionFileFilter filterTxt = new ExtensionFileFilter("txt", "Text file (*.txt)");
	this.chooser.setFileFilter(filterTxt);
	
	ExtensionFileFilter filterXml = new ExtensionFileFilter("xml", "XML file (*.xml");
	this.chooser.setFileFilter(filterXml);
}

private JPanel formatPanelButtons() {

	//panel
	JPanel panel = new JPanel();
	panel.setBackground(this.getBackground());
	panel.setBorder(new EtchedBorder());
	panel.setBounds(380, 20, 120, 300);
	panel.setVisible(true);
	panel.setEnabled(true);
	
	/*Butons*/
	this.btnImportExportArray10 = new JButton();
	this.btnImportExportArray10.setText("Array 10");
	this.btnImportExportArray10.setToolTipText("Import daily rainfall from the text file and export to the data banking");
	this.btnImportExportArray10.setBounds(10, 10, 100, 25);
	
	this.btnImportExportArray20 = new JButton();
	this.btnImportExportArray20.setText("Array 20");
	this.btnImportExportArray20.setToolTipText("Import daily rainfall from the text file and export to the data banking");
	this.btnImportExportArray20.setBounds(10, 45, 100, 25);

	this.btnExportData = new JButton();
	this.btnExportData.setText("Export");
	this.btnExportData.setToolTipText("Export daily data");
	this.btnExportData.setBounds(10, 80, 100, 25);

	this.btnChart = new JButton();
	this.btnChart.setText("Chart");
	this.btnChart.setToolTipText("Display the time series chart");
	this.btnChart.setBounds(10, 115, 100, 25);

	this.btnClose = new JButton();
	this.btnClose.setText("Close");
	this.btnClose.setToolTipText("Close this window");
	this.btnClose.setBounds(10, 150, 100, 25);

	this.btnOneGauge = new JButton();
	this.btnOneGauge.setText("One gauge");
	this.btnOneGauge.setToolTipText("xx");
	this.btnOneGauge.setBounds(10, 185, 100, 25);
	
	this.btnAllGauges = new JButton();
	this.btnAllGauges.setText("All gauges");
	this.btnAllGauges.setToolTipText("xx");
	this.btnAllGauges.setBounds(10, 220, 100, 25);


	panel.add(btnImportExportArray10);
	panel.add(btnImportExportArray20);
	panel.add(btnExportData);
	panel.add(btnChart);
	panel.add(btnClose);
	panel.add(btnOneGauge);
	panel.add(btnAllGauges);
	
	return panel;
}

private JPanel formatPanelTree() {
	JPanel panel = new JPanel();
	JPanel panelDir = new JPanel();
	JPanel panelFiles = new JPanel();
	
	JTree tree = new JTree();
	JScrollPane scrollDir;
	
	//panel
	panel.setBackground(this.getBackground());
	panel.setBounds(20, 20, 340, 300);
	panel.setVisible(true);
	panel.setEnabled(true);
	

	//panelDir
	panelDir.setBackground(this.getBackground());
	panelDir.setBorder(new EtchedBorder());
	panelDir.setBounds(0, 0, 340, 150);
	panelDir.setVisible(true);
	
	//panelDir
	panelFiles.setBackground(this.getBackground());
	panelFiles.setBorder(new EtchedBorder());
	panelFiles.setBounds(0, 170, 340, 130);
	panelFiles.setVisible(true);

// //build JTree
this.tree = tree;
tree = this.buildTreeDirectories();
tree.setBackground(this.getBackground());
tree.setVisible(true);
tree.setRootVisible(false);

	//add tree to tree Panel
	panelDir.add(tree);
	
	//add to main Panel
	panel.add(panelDir);
	panel.add(panelFiles);
	
	return panel;
}

public JTree buildTreeDirectories(){
	DefaultMutableTreeNode root = new DefaultMutableTreeNode("root", true);

	this.getListFiles(root, new File("C:/Java/Eclipse/workspace/"));
	
	JTree tree = new JTree(root);
	
	return tree;
}

private void getListFiles(DefaultMutableTreeNode node, File f) {

	if(!f.isDirectory()){

// System.out.println("Eh um arquivo - ");

	}
	else{

// System.out.println("\nEh um diretorio");
DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
node.add(child);
File fileList[] = f.listFiles();
for(int i = 0; i < fileList.length; i++)
getListFiles(child, fileList[i]);
}

}


private void insertDataIntoTable() {
	// TODO Auto-generated method stub
	
}

}
[/code]

Espero que vocês consigam e possam me ajudar!!!

Criando uma classe main que rode esta acho que fica fácil de entender o código :smiley: Pelo menos espero que sim.

[]'s
Paz

nao li muito o teu codigo mais vou te passar um site q pode te ajudar
http://www.exampledepot.com/egs/javax.swing.tree/pkg.html

Falow
Bernardo Sanson

Blz cara, vou dar uma olhada!
abraço