import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; public class Puu3 extends JPanel implements TreeSelectionListener, ItemListener{ JTree puu; JTextField tf=new JTextField(10); JTextArea ala=new JTextArea(); FailiMenyyMudel menyymudel=new FailiMenyyMudel(); JComboBox asukohavalik; public Puu3(){ JSplitPane jagaja=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); JPanel parempaneel=new JPanel(new BorderLayout()); parempaneel.add(tf, BorderLayout.NORTH); parempaneel.add(new JScrollPane(ala), BorderLayout.CENTER); JPanel vasakpaneel=new JPanel(new BorderLayout()); asukohavalik=new JComboBox(menyymudel); asukohavalik.setEditable(true); asukohavalik.addItemListener(this); puu=new JTree(new FailipuuMudel("d:\\")); vasakpaneel.add(asukohavalik, BorderLayout.NORTH); vasakpaneel.add(new JScrollPane(puu), BorderLayout.CENTER); jagaja.setLeftComponent(vasakpaneel); jagaja.setRightComponent(parempaneel); puu.addTreeSelectionListener(this); setLayout(new java.awt.BorderLayout()); add(jagaja); // add(tf); } public void itemStateChanged(ItemEvent e){ puu.setModel(new FailipuuMudel(e.getItem().toString())); } public void valueChanged(TreeSelectionEvent e){ Object[] jada=puu.getSelectionPath().getPath(); StringBuffer sb=new StringBuffer(jada[0].toString()); for(int i=1; i "+jada[i]); } tf.setText(sb.toString()); try{ File f=(File)puu.getSelectionPath().getLastPathComponent(); if(f.isFile()){ BufferedReader failist=new BufferedReader(new FileReader(f)); StringBuffer sb2=new StringBuffer(); for(String rida=failist.readLine(); rida!=null; rida=failist.readLine()){ sb2.append(rida+"\n"); } ala.setText(sb2.toString()); failist.close(); } }catch(Exception ex){ex.printStackTrace();} } public static void main(String[] arg){ JFrame f=new JFrame("Puu"); f.add(new Puu3()); f.setSize(400, 400); f.setVisible(true); } }