import java.io.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; public class Puu2 extends JPanel implements TreeSelectionListener{ JTree puu=new JTree(new FailipuuMudel());; JTextArea ala=new JTextArea(); JSplitPane jaotuspaneel=new JSplitPane(); public Puu2(){ jaotuspaneel.setLeftComponent(new JScrollPane(puu)); jaotuspaneel.setRightComponent(new JScrollPane(ala)); setLayout(new java.awt.BorderLayout()); add(jaotuspaneel); puu.addTreeSelectionListener(this); } public void valueChanged(TreeSelectionEvent e){ File f=(File)puu.getLastSelectedPathComponent(); if(!f.isFile()){return;} try{ StringBuffer puhver=new StringBuffer(); BufferedReader failist=new BufferedReader(new FileReader(f)); for(String rida=failist.readLine(); rida!=null; rida=failist.readLine()){ puhver.append(rida+"\n"); } failist.close(); ala.setText(puhver.toString()); }catch(IOException ioe){ ioe.printStackTrace(); } } public static void main(String[] arg){ JFrame f=new JFrame("puu"); f.add(new Puu2()); f.setSize(500, 500); f.setVisible(true); } }