Solved

Running an Applet (jdk 1.1.7) in IE 5

Posted on 2001-06-14
5
183 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
ID: 6192443
please post your code for reference....
0
 

Author Comment

by:FFengler
ID: 6192492
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
ID: 6193336
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
ID: 6193921
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
ID: 9033793
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 80
firstswap challenge 20 68
Java - Why doesn't this JFrame work 3 43
tomcat not starting 6 31
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

896 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

17 Experts available now in Live!

Get 1:1 Help Now