codice:
public void dir(final GridBagConstraints lim, final GridBagLayout layout){
DefaultMutableTreeNode top = new DefaultMutableTreeNode("C:\\prova");
final JTree c17 = new JTree(top);
c17.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
c17.addTreeSelectionListener(new TreeSelectionListener(){
public void valueChanged(TreeSelectionEvent event){
node = (DefaultMutableTreeNode) c17.getLastSelectedPathComponent();
File f = new File(node.toString());
addChildrens(f.listFiles());
if((node.isRoot() || (!node.isLeaf()) )){
try {
//repaint();
cornice(null, lim, layout);
//repaint();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
try {
//repaint();
cornice(node.toString(), lim,layout);
//repaint();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
});
lim.gridx = 0;
lim.gridy = 2;
lim.gridwidth = 2;
lim.gridheight = 2;
lim.fill= GridBagConstraints.NORTHEAST;
layout.setConstraints(c17, lim);
add(c17);
}
//visualizza immagine file
public void cornice(String path, GridBagConstraints lim, GridBagLayout layout) throws IOException, URISyntaxException{
// Component c18 = new JLabel(new ImageIcon("ciao"));
Component c18 = null;
String strFolderPath = null;
String strFileName = null;
File imagePath=null;
BufferedImage image=null ;
if(path==null)
{
strFolderPath = "C:/prova";
strFileName = "vuota.jpg";
imagePath = new File(strFolderPath, strFileName);
}
else
{
ArrayList<String> ris = scomponipath(path);
imagePath = new File(ris.get(1), ris.get(0));
}
// Contiene il riferimento al file da aprire
System.out.println(path);
image = ImageIO.read(imagePath);
ImageIcon I = new ImageIcon(image);
c18 = new JLabel(I);
c18.setBackground(Color.WHITE);
repaint();
// JLabel l = new JLabel();
// OverlayLayout cont = new OverlayLayout((Container) c18);
// l.setLayout(cont);
lim.gridx = 0;
lim.gridy = 2;
lim.gridwidth = 14;
lim.gridheight = 2;
lim.fill = GridBagConstraints.CENTER;
layout.setConstraints(c18,lim);
add(c18);
repaint();
}