Solved

Running an Applet (jdk 1.1.7) in IE 5

Posted on 2001-06-14
5
180 Views
Last Modified: 2013-11-23
Hi,

I try to run an applet contenting a JTree in IE 5 but the Tree does not expand/collapse and the Scrollbar is not working. Only if I force a repaint (by changing the screen) the expanded Tree is visible.

What can I do to make it run ?

FFengler
0
Comment
Question by:FFengler
5 Comments
 
LVL 2

Expert Comment

by:iDeb
Comment Utility
please post your code for reference....
0
 

Author Comment

by:FFengler
Comment Utility
Here's the code


There are 4 classes altogether, JDK 1.1.7 is used.

import java.awt.*;
import java.applet.*;
import com.sun.java.swing.JScrollPane;
import com.sun.java.swing.JTree;
import com.sun.java.swing.JButton;
import java.net.*;
import com.sun.java.swing.event.*;

public class PDHApplet extends Applet
{
    private PdhInput pdh;
   
      public void init()
      {
            
            
            //{{INIT_CONTROLS
            setLayout(null);
            setBackground(java.awt.Color.lightGray);
            setSize(693,540);
            
            try{
            pdh=new PdhInput(getDocumentBase());
            pdh.loadPdh();
            Baum b=new Baum();
            JTree1 = new com.sun.java.swing.JTree(b.createTree(pdh));
        }catch(Exception ex){}
            JScrollPane1.setOpaque(true);
            add(JScrollPane1);
            
            JScrollPane1.setBounds(36,48,624,435);
            JScrollPane1.getViewport().add(JTree1);
            JTree1.setBounds(0,0,621,432);
            //}}
      
          TreeControl control=new TreeControl();
          JTree1.addTreeExpansionListener(control);
      }
      
      
      //{{DECLARE_CONTROLS
      com.sun.java.swing.JScrollPane JScrollPane1 = new com.sun.java.swing.JScrollPane();
      com.sun.java.swing.JTree JTree1;
      //}}



      public class TreeControl implements TreeExpansionListener{
          public void treeCollapsed(TreeExpansionEvent event){
              JTree1.repaint();
          }
          
          
          public void treeExpanded(TreeExpansionEvent event){
              JTree1.repaint();
          }
      }
}



import com.sun.java.swing.*;
import com.sun.java.swing.tree.*;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.net.*;

public class Baum

{

   
   
    private Vector pdhdata;
    private PdhEintrag entry;
    private int s;
    private Hashtable nodeList=new Hashtable();
   
   
 public DefaultMutableTreeNode createTree(PdhInput pdh)
 {
    int count=0;
    pdhdata=pdh.getPdh();
    s=pdhdata.size();
    DefaultMutableTreeNode parent;
    DefaultMutableTreeNode node;
    DefaultMutableTreeNode wurzel=new DefaultMutableTreeNode("Produkthierarchie");
   
   
   while(count<=s){
    entry=(PdhEintrag)pdhdata.elementAt(count);
    node=new DefaultMutableTreeNode(entry.getName());
    nodeList.put(entry.getName(),node);
    if (entry.getParent().equals("ROOT")){
      wurzel.add(node);
    }else{
      parent=this.findNode(entry.getParent(),nodeList);
      if (parent==null){
        int anz=wurzel.getChildCount();
        break;
      }else{
        parent.add(node);
      }
    }
    count++;
   
   };
  //  this.saveTree(wurzel);
    return wurzel;
 }
 
 
 private DefaultMutableTreeNode findNode(String name, Hashtable nodeList){
 
   //Enumeration e;
   DefaultMutableTreeNode node=new DefaultMutableTreeNode();
   if (nodeList.containsKey(name)){
     return (DefaultMutableTreeNode) nodeList.get(name);
   } else{
     return null;
   }
 }

 
}



import java.awt.*;
import java.util.*;
import java.io.*;
import java.net.*;

public class PdhInput
{
  private Vector pdhdata= new Vector();
  private final String FILENAME="PDH.csv";
  private URL fileUrl;
 
  public PdhInput(URL baseURL) throws Exception{
    String path=baseURL.getFile();
    path=path.substring(0,path.lastIndexOf('/')+1);
    path=path+FILENAME;
    fileUrl=new URL(baseURL.getProtocol(),baseURL.getHost(),baseURL.getPort(),path);
  }
 
  public void loadPdh()throws Exception
  {
    int pos;
    int index;
    int i;

    StringTokenizer T;
   
   
    try{
        BufferedReader br = new BufferedReader( new InputStreamReader(fileUrl.openStream()) );
        String str;
        while((str=br.readLine())!=null){
          T=new StringTokenizer(str,";");
          String s1=T.nextToken();
          String s2=T.nextToken();
          String s3=T.nextToken();
          String s4=T.nextToken();
          String s5=T.nextToken();
          s4=s4.concat(" ");
          s4=s4.concat(s5);
         
          PdhEintrag e=new PdhEintrag(s1,s2,s3,s4);
          pdhdata.addElement(e);
        }
        br.close();
    }catch(IOException e){}
  }

  public Vector getPdh()
  {
      return this.pdhdata;
  }

 
 
 
 
 
}

public class PdhEintrag
{
    private String name;
    private String parent;
    private String stufe;
    private String nummer;
   
    public PdhEintrag()
    {
        name="";
        parent="0";
        stufe="0";
        nummer="0";
    }
   
    public PdhEintrag(String nummer, String stufe, String parent, String name)
    {
      this.nummer=nummer;
      this.name=name;
      this.parent=parent;
      this.stufe=stufe;
    }
   
    public void setName(String name)
    {
        this.name=name;
    }
    public void setParent(String parent)
    {
        this.parent=parent;
    }
    public void setStufe(String stufe)
    {
        this.stufe=stufe;
    }
    public void setNummer(String nummer)
    {
        this.nummer=nummer;
    }
   
   
    public String getNummer()
    {
        return nummer;
    }
   
    public String getParent()
    {
        return parent;
    }
    public String getStufe()
    {
        return stufe;
    }
    public String getName()
    {
        return name;
    }
   
    public void setEntry(String nummer, String stufe, String parent, String name)
    {
        this.nummer=nummer;
        this.name=name;
        this.parent=parent;
        this.stufe=stufe;
    }
   
    public PdhEintrag getEntry()
    {
        return this;
    }
   
}
0
 
LVL 7

Expert Comment

by:Igor Bazarny
Comment Utility
Hi,

I would suggest to update swing version to 1.1.1 (latest 1.1 compatible version). Probably it will solve many problems.

Regards,
Igor Bazarny
Brainbench MVP for Java 1
www.brainbench.com
0
 
LVL 1

Accepted Solution

by:
tonus earned 50 total points
Comment Utility
Hi,
  Instead of painting JTree, paint the applet itself by calling the repaint() method whereever you called the JTree.repaint(). Override the paint method as given below.


public void paint(Graphics g){
this.validate();
super.paint(g);
}

this.validate() validates all the components added to the applet and repaints the component which has been changed.


 
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to tonus]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now