Solved

Applet not displaying properly

Posted on 2012-03-12
19
527 Views
Last Modified: 2012-04-25
Hi,

I built an applet that used to work fine, but recently for some users the applet's GUI is not displaying properly. I attached applet1.jpg which is how it should appear and works for most people, and applet2.jpg is what few people see on their screen.

So far I found that
1. This happens whether applet runs internally or from the web
2. It happens on all browsers (tried on IE, Chrome), regardless of versions.
3. Complete uninstallation of JRE and reinstallation didn't fix.
4. Uninstallation/reinstallation of graphic driver, changing resolution didn't fix

Do you know what can possibly cause this problem? Any help would be appreciated.
Thanks
applet1.jpg
applet2.jpg
0
Comment
Question by:shepp_it
  • 11
  • 7
19 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
what is the html, say contetnst of APPLET tag, which you use to display the applaet.
It looks like the difference is in the heiwght width alliocated to te appleat - do you specify it directly in the HTML ?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
>applet runs internally

what do you mean by this ?
0
 

Author Comment

by:shepp_it
Comment Utility
Yes, I specified the width as a part of HTML code (in JSP) <applet width="893" height="588" code="org.shepp.advmdr.JavaApplet" archive="ADVMDRApplet.jar">

"applet runs internally" I mean this happens for both when the applet is loaded from the web server or local internal test server
0
 
LVL 1

Expert Comment

by:RodSingh
Comment Utility
I would check if it is a certificate related issue where you would have to resign the jar file -- just a guess.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Maybe you could try to sepcify width and height in % - maybe it would help

DO you emeann  it used to open fine on the same machine, same browser - and now opens ion smaller window suddenly?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
You may try to use Object elmenet instead of Applet as applet is mopre and more consideerd deprectaed, maybe that would help
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
check this:
http://docs.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/using_tags.html

you probably want to run some investigation to understand what specific situations cause
 these incorrect display and if it is browser independent (this is of course first thing which would come to mind when you think of the causes of such situation) then to try to understand at what point it suddenly starts happening

If you could post just GUI part of your code, I could try to run it in y browsers and see how it looks
0
 

Author Comment

by:shepp_it
Comment Utility
I use NetBeans IDE to built the applet, and if I use
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
for the window theme. I have another example that causes the same problem. here is the snippet of code:

package org.me.hello;


import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.UIManager;
/**
 *
 * @author spark
 */
public class MyApplet extends javax.swing.JApplet {

    /** Initializes the applet MyApplet */
    public void init() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception e) {
            // Just accept the default L&F
        }
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                    //getContentPane().setBackground(Color.white);
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
...

and uses followings html

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Applet and Servlet Communication</h1>
        <applet width="500" height="350" code="org.me.hello.MyApplet" archive="JavaApplet.jar"/>
    </body>
</html>
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
I will still need the actual UI contents
if I want to  play with it
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:shepp_it
Comment Utility
Ok here is the entire java code for applet part. I also attched a screenshot on my computer which displays properly and another computer where it doesn't. Applet width is around 500px.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MyApplet.java
 *
 * Created on May 21, 2010, 11:20:52 AM
 */

package org.me.hello;


import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Vector;
import javax.swing.UIManager;
/**
 *
 * @author spark
 */
public class MyApplet extends javax.swing.JApplet {

    /** Initializes the applet MyApplet */
    public void init() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            // Just accept the default L&F
        }
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                    //getContentPane().setBackground(Color.white);
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        myTF = new javax.swing.JTextField();
        btSubmit = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        myTA = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();

        jLabel1.setText("What is your name?");

        btSubmit.setText("Submit");
        btSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSubmitActionPerformed(evt);
            }
        });

        myTA.setColumns(20);
        myTA.setRows(5);
        jScrollPane1.setViewportView(myTA);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(myTF, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btSubmit))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(myTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btSubmit))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(107, Short.MAX_VALUE))
        );

        jButton1.setText("jButton1");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addContainerGap(292, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>

    private void btSubmitActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    // Variables declaration - do not modify
    private javax.swing.JButton btSubmit;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea myTA;
    private javax.swing.JTextField myTF;
    // End of variables declaration

}
applet4.jpg
applet5.jpg
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
But you didn't provide any 500x100 picture and I didn't seem to see provision for it in the code. Other than that, when I make sure I have sufficiently wide window, say:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Applet and Servlet Communication</h1>
        <applet width="500" height="500" code="MyApplet" />
    </body>
</html>

Open in new window


I have no problems with the applet - it shows both in IE and Firefox with full view.


picture
0
 

Author Comment

by:shepp_it
Comment Utility
I don't have this problem either. Most people don't. But for some people it doesn't display  correctly.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Still, I would increase the height and width values on your HTML page with the applet
and ask those people who experonce it if they see any difference
0
 

Author Comment

by:shepp_it
Comment Utility
Increasing the height and width didn't work. I think this is a problem with the computer not the applet. I found that it doesn't display GUI component correctly even when I try to run a standard java desktop application. it works fine on other computers.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
so you mean it does not resize JFrame when you specify dimensions in Java application ?

Maybe yyou need to reinstall java there ?
0
 

Author Comment

by:shepp_it
Comment Utility
I reinstalled java but it didn't fix the problem. I'm wondering if this is something to do with hardware now, maybe raphic card or RAM. Still searching for an answer...
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
If you are saying that this affects not only applets but any java applications, one thing I would create a simple java application-test which illustrates  the issue
application is a much better test, as it is not related to any browser, etc.
Then really compare if all those cases where it runs incorrectly have the same graphics card.
This seems strange to me, as I never herad anything of the kind, but there are so many werd things.
But I'd start with having the simplese possible application which couild illustrate the difference.
0
 

Author Comment

by:shepp_it
Comment Utility
I can't narrow down the problem any further. One thing I noticed is though, two people who are having this problem use browser with higher zoom setting than 100%. Maybe this affected GUI resolution or calibration of pixel size? I know it makes no sense but anything can happen in Windows I think.

Another possible reason I can think of is, maybe java code generated by GUI builder in NetBeans aren't stable or this conflicts with other setting.

Have you ever heard of any issue with above two situation?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
Comment Utility
Your first point in my mind sounds quite plausible and seesm more probable than hardware assumption you had before.
Check if that is the rulee which holds in all cases where it fails.

I haven't heard about such issue with Netbeans GUI Builder, though I do believe that it is rather limited thing and prefer not to use it as it really reduces flexibitlty of how you can modify and experiment with yourr GUI.
It is true that some rathe simple GUI it can build a little bit more beautiful - but on both low-end cases where you rather want to learn how to do it yourself and high-end cases where you really want sophisticationand flexibility - it is inappropriate for use.
So I prefer not to use it at all.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

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)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

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

8 Experts available now in Live!

Get 1:1 Help Now