The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

My suggestion ::

Posted by Kumaran on May 28, 2001 at 2:11 AM

Hi,
Set the security policy to access the local files from
Browser.
Without setting policies, a local file can't be opened from
Browser.

O.k.
Still you face problems, Just mail me , i will tell you
how to set the polices.
O.k
Bye .
Kumaran.


> Dear sir,
> I have a problem in soving a swing tree question:
> I am running a tree on a browser(IE). The tree appears on the browser but when i click the leaf node, the required file(whose name is on the leaf node) does not open on the right side of the split pane.If i run the similar code on JFrame, it runs well and the leaf files also open up when required.
> Kindly advise in detail where I am wrong. I am writing below the whole code for your reference(contents have no value). If possible please redo this code and send me back.

> Thank you.
> MUNISH(ohrim@rediffmail.com)
> see code below:

>
> import javax.swing.*;
> import javax.swing.tree.*;
> import javax.swing.event.*;
> import java.awt.*;
> import java.awt.event.*;
> import java.net.*;
> import java.io.*;
> import com.sun.java.swing.plaf.windows.*;
> /*
>
>
>
*/
> public class good extends JApplet
> {
> Container container;
> DefaultMutableTreeNode root;
> JScrollPane treescrollpane;
> JScrollPane editorscrollpane;
> JEditorPane editorpane;
> JPanel panel;

> String str1,str2;

> public void init()
> { container = this.getContentPane();
> str2=getParameter( "colla" );
> str1=getParameter( "collb" );

> try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.window
> s.WindowsLookAndFeel");
> SwingUtilities.updateComponentTreeUI(container);}
> catch(Exception e) {System.out.print("could not open look and feel");}

>
> createTreeNodes();

> JTree tree = new JTree(root);
> tree.getSelectionModel().setSelectionMode(TreeSelectionModel
> .SINGLE_TREE_SELECTION);
> tree.addTreeSelectionListener(new Selectionlistener());

> treescrollpane= new JScrollPane(tree);

> editorpane = new JEditorPane();
> editorscrollpane = new JScrollPane(editorpane);
> JSplitPane splitpane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, treescrollpane, editorscrollpane);
> try{
> container.add(splitpane);

> // addWindowListener(new WindowEventHandler());

> //setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
> ;
> setSize(400,400);
> // show();
> }catch(Exception e){System.out.print("munish");}
> //UIManager.put("Tree.openIcon", new IconUIResource(

> //new ImageIcon("NUM2.gif")));

> }

> public void createTreeNodes()
> {
> root = new DefaultMutableTreeNode("c:\\");

> DefaultMutableTreeNode col11= new DefaultMutableTreeNode(str1);
> root.add(col11);
> DefaultMutableTreeNode col12= new DefaultMutableTreeNode("program2");
> DefaultMutableTreeNode col13= new DefaultMutableTreeNode("program3");
> root.add(col12);
> root.add(col13);
> DefaultMutableTreeNode col31 = new DefaultMutableTreeNode("Hyperlink.java");
> DefaultMutableTreeNode col33 = new DefaultMutableTreeNode(str2);
> DefaultMutableTreeNode col32 = new DefaultMutableTreeNode("2.html");
> DefaultMutableTreeNode col41 = new DefaultMutableTreeNode("4.html");
> DefaultMutableTreeNode col42 = new DefaultMutableTreeNode("5.html");
> DefaultMutableTreeNode col43 = new DefaultMutableTreeNode("Hyperlink.java");
> DefaultMutableTreeNode col44 = new DefaultMutableTreeNode("7.html");


>
> //DefaultMutableTreeNode col33 = new DefaultMutableTreeNode("3.html");

> col11.add(col31);
> col11.add(col32);
> col11.add(col33);

> col12.add(col41);
> col12.add(col42);
> col13.add(col43);
> col13.add(col44);

>
> }

> class Selectionlistener implements TreeSelectionListener//nested class
> {
> URL url;

> public void valueChanged(TreeSelectionEvent se){
> JTree tree = (JTree) se.getSource();
> DefaultMutableTreeNode selectednode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
> String selectednodename = selectednode.toString();

> if(selectednode.isLeaf())
> {
> String urlString = "file:"+ System.getProperty("user.dir")+ System.getProperty("file.separator")+selectednodename;

> //System.out.println(urlString);

> try{
> url = new URL(urlString);}
> catch(MalformedURLException urlex){
> //System.out.print("iMarlformed URL Exception.i");}
> try{
> editorpane.setPage(url);}
> catch(IOException ex){
> System.out.println("the selected file was not found");
> System.out.print(ex);}
> }
> }
> }

> class Windoweventhandler extends WindowAdapter
> {
> public void WindowClosing(WindowEvent evt)
> {
> System.exit(0);
> }
> }

>
> //public void paint(Graphics g){

>
> }


>
> }






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us