We help IT Professionals succeed at work.

Applet not displaying properly

shepp_it
shepp_it asked
on
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
Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:
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 ?
Awarded 2011
Awarded 2011

Commented:
>applet runs internally

what do you mean by this ?

Author

Commented:
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

Commented:
I would check if it is a certificate related issue where you would have to resign the jar file -- just a guess.
Awarded 2011
Awarded 2011

Commented:
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?
Awarded 2011
Awarded 2011

Commented:
You may try to use Object elmenet instead of Applet as applet is mopre and more consideerd deprectaed, maybe that would help
Awarded 2011
Awarded 2011

Commented:
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

Author

Commented:
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>
Awarded 2011
Awarded 2011

Commented:
I will still need the actual UI contents
if I want to  play with it

Author

Commented:
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
Awarded 2011
Awarded 2011

Commented:
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

Author

Commented:
I don't have this problem either. Most people don't. But for some people it doesn't display  correctly.
Awarded 2011
Awarded 2011

Commented:
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

Author

Commented:
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.
Awarded 2011
Awarded 2011

Commented:
so you mean it does not resize JFrame when you specify dimensions in Java application ?

Maybe yyou need to reinstall java there ?

Author

Commented:
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...
Awarded 2011
Awarded 2011

Commented:
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.

Author

Commented:
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?
Awarded 2011
Awarded 2011
Commented:
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.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.