JApplet display

I am getting strange behavior from my JApplet with swing GUI. Applet loads fine but only becomes visible when the mouse goes over components. If you scroll, it disappears again. Runs fine as application. Tried repaint() method, same result.
Any ideas?
public class IncDataApplet extends JApplet {
public IncDataApplet() {
IncDataGUI id = new IncDataGUI();
id.open();
BorderPanel mv = (BorderPanel) id.getMainView();
this.add(mv);
this.setVisible(true);
public void init()
this.repaint();
public void start()
this.repaint();
public void paint(Graphics g)
this.repaint();
}

Anyway, try to do this:
public class IncDataApplet extends JApplet {
public IncDataApplet() {}
    public void init() {
        IncDataGUI id = new IncDataGUI();
        id.open();
        BorderPanel mv = (BorderPanel) id.getMainView();
     java.awt.Container con = getContentPane();
        con.setLayout(new java.awt.BorderLayout());
     con.add(mv);
}

Similar Messages

  • JApplet displaying too large in IE with JRE 1.5.0_06

    In my html, I have defined my width and height as 856 and 600 respectively.
    With JRE 1.4, the applet showed at the correct size. But I've upgraded to JRE 1.5.0_06 and now the applet is displaying at 1070 x 750 - that's an additional 25% for each dimension.
    At the beginning of the init() method, I have tried doing:
    this.setSize(856, 600);
    this.validate();but immediately printing out this.getWidth() and this.getHeight() still report 1070 x 750.
    At the end of the init() method, I repeat the
    this.setSize(856, 600);
    this.validate();code and the this,getWidth() and this.getHeight() now informs me of the desired 856 x 600 dimensions - but the applet is still visually too big on the screen.
    Don't get the problem with Mozilla or Firefox - only with IE (v6.0).
    Anyone have any ideas?
    Cheers,
    James

    This does not seem specific to one machine. I got thi crash once on my machine and I have customer complaints where they have reported this issue on several of their machines.

  • Integer data column alignment

    Hello,
    My JApplet displays a table of values in the required alignment except for columns of integers.
    How do I effect alignment of the integer value columns
    starting precisely to the right side of the column field without impacting alignment of the other columns?
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.text.*;
    import javax.swing.*;
    import java.net.*;
    import java.util.*;
         <applet code= "Table" width=700 height=200>
         </applet>
    public class Table extends JApplet {
         final int MAX_ROW = 5;
         final int MAX_FACTOR_COL = 3;
         JTextArea TA;
         String location[] = { "City", "Anycity", "No City", "nowhere CITY", "CITY CA"};
         int population[] = new int[MAX_ROW];
         double factor[][] = new double[MAX_ROW][MAX_FACTOR_COL];
         int fatalities[] = new int[MAX_ROW];
         String output = "";
         public void init() {
              GUI();
              TA.setText( results() );
         private void GUI(){
              setLayout( new BorderLayout() );
              Box box = Box.createVerticalBox();
              TA = new JTextArea(output, 80,100);
              TA.setEditable(false);
              add(TA);
              box.add( new JScrollPane( TA));
              add(box, BorderLayout.CENTER);
         } // end GUI()
         private String results(){
              int i;
              int j;
              for( i = 0; i<MAX_ROW; i++){
                   population[i] = i*i*i*i;
                   for (j = 0; j < MAX_FACTOR_COL; j++){
                        factor[i][j] = 0.123 *(i + j);
                   fatalities[i] = (int)(population[i] * i * 0.1);
                        Formatter f = new Formatter();     
                        f.format("%s\t\t%8d\t%6.4f\t%6.4f\t%6.4f\t%8d",  location, population[i], factor[i][0], factor[i][1], factor[i][2], fatalities[i]);
                        output += "\t" + f + "\n";
              return output;
         }// end results()
    } // end Table class
    OK, I have tried one solution by conversion/manipulation of string in concert with placing space character to shift digit characters to right side. It is interesting to notice that the increment generally requires two space characters per digit placeholder since apparently not all types of characters are spaced equally in the string. This solution requires advance knowledge of the maximum number of digits representing integers in order to modify the placeholder logic. But, hey! I'm still interested in a better solution. The solution code is as follows:
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.text.*;
    import javax.swing.*;
    import java.net.*;
    import java.util.*;
         <applet code= "Table" width=700 height=200>
         </applet>
    public class TableSolution1 extends JApplet {
         final int MAX_ROW = 5;
         final int MAX_FACTOR_COL = 3;
         JTextArea TA;
         String location[] = { "City", "Anycity", "No City", "nowhere CITY", "CITY CA"};
         int population[] = new int[MAX_ROW];
         double factor[][] = new double[MAX_ROW][MAX_FACTOR_COL];
         int fatalities[] = new int[MAX_ROW];
         String output = "";
         public void init() {
              GUI();
              TA.setText( results() );
         private void GUI(){
              setLayout( new BorderLayout() );
              Box box = Box.createVerticalBox();
              TA = new JTextArea(output, 80,100);
              TA.setEditable(false);
              add(TA);
              box.add( new JScrollPane( TA));
              add(box, BorderLayout.CENTER);
         } // end GUI()
         private String results(){
              int i;
              int j;
              String spop[] = new String[MAX_ROW];
              String sfat[] = new String[MAX_ROW];
              for( i = 0; i<MAX_ROW; i++){
                   population[i] = i*i*i*i;
                   // prepare population data alignment
                   if(100<population[i]  && population[i] < 1000)
                        spop[i] = "          ";
                   else if(10<population[i]  && population[i] < 100)
                        spop[i] = "            ";
                   else
                        spop[i] = "              ";
                   spop[i] = spop[i] + population;
                   for (j = 0; j < MAX_FACTOR_COL; j++){
                        factor[i][j] = 0.123 *(i + j);
                   fatalities[i] = (int)(population[i] * i * 0.1);
                   // prepare fatalities data alignment
                   if(100<fatalities[i] && fatalities[i] < 1000)
                        sfat[i] = " ";
                   else if(10<fatalities[i] && fatalities[i] < 100)
                        sfat[i] = " ";
                   else
                        sfat[i] = " ";
                   sfat[i] = sfat[i] + fatalities[i];
                        Formatter f = new Formatter();     
                        f.format("%s\t\t%s\t%6.4f\t%6.4f\t%6.4f\t%s", location[i], spop[i], factor[i][0], factor[i][1], factor[i][2], sfat[i]);
                        output += "\t" + f + "\n";
              return output;
         }// end results()
    } // end TableSolution1 class
    Message was edited by:
    AnalysisGuru
    Message was edited by:
    AnalysisGuru

    NUMBER datatype don't have formatting when they are saved in database, if you need to format the output use TO_CHAR() function,
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/functions181.htm#i79330

  • Example of WAIT and CONTINUE using checkBox and thread and getTreeLock()

    I had so much trouble with this that I descided to
    post if incase it helps someone else
    // Swing Applet example of WAIT and CONTINUE using checkBox and thread and getTreeLock()
    // Runs form dos window
    // When START button is pressed program increments x and displys it as a JLabel
    // When checkBox WAIT is ticked program waits.
    // When checkBox WAIT is unticked program continues.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class Wc extends JApplet {
    Display canvas;//drawing surface is displayed.
    Box buttonPanel;
    Box msgArea;
    public static JButton button[] = new JButton [2];
    public static JCheckBox checkBox[] = new JCheckBox[2];
    public static JLabel msg[] = new JLabel [2];
    String[] buttonDesc ={"Start","Quit"};
    public static final int buttonStart = 0;
    public static final int buttonQuit = 1;
    String[] checkBoxDesc ={"Wait"};     
    public static final int checkBoxWait = 0;
    public boolean wait;
    public Graphics g;
    //================================================================
    public static void main(String[] args){
    Frame f = new Frame();
    JApplet a = new Wc();
    f.add(a, "Center"); // Add applet to window
    a.init(); // Initialize the applet
    f.setSize(300,100); // Set the size of the window
    f.show(); // Make the window visible
    f.addWindowListener(
    new WindowAdapter(){
    public void windowClosing(WindowEvent e){System.exit(0);}
    }// end main
    //===================================================
    public void init() {
    canvas = new Display();
    setBackground(Color.black);
    getContentPane().setLayout(new BorderLayout(3,3));
    getContentPane().add(canvas, BorderLayout.CENTER);
    buttonPanel = Box.createHorizontalBox();
    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    int sbZ;
    // add button
    button[0] = new JButton(buttonDesc[0]);
    button[0].addActionListener(canvas);
    buttonPanel.add(button[0]);
    button[1] = new JButton(buttonDesc[1]);
    button[1].addActionListener(canvas);
    buttonPanel.add(button[1]);
    // add checkBox
    sbZ=0;
    checkBox[sbZ]=new JCheckBox(checkBoxDesc[sbZ]);
    checkBox[sbZ].setBackground(Color.white);
    checkBox[sbZ].setOpaque(true);
    checkBox[sbZ].addActionListener(canvas);
    buttonPanel.add(checkBox[sbZ]);
    msgArea = Box.createVerticalBox(); // add message
    sbZ=0;
    msg[sbZ]=new JLabel("1",JLabel.LEFT);
    msg[sbZ].setOpaque(true);
    msg[sbZ].setBackground(Color.black);
    msg[sbZ].setForeground(Color.red);
    msgArea.add(msg[sbZ]);
    getContentPane().add(msgArea, BorderLayout.SOUTH);
    } // end init();
    //===================================================
    public void stop(){canvas.stopRunning();}
    //===================================================
    // The following nested class represents the drawing surface
    // of the applet and also does all the work.
    class Display extends JPanel implements ActionListener, Runnable {
    Image OSI;
    Graphics OSG; // A graphics context for drawing on OSI.
    Thread runner; // A thread to do the computation.
    boolean running; // Set to true when the thread is running.
    public void paintComponent(Graphics g) {
    if (OSI == null) {
    g.setColor(Color.black);
    g.fillRect(0,0,getWidth(),getHeight());
    else {g.drawImage(OSI,0,0,null);}
    }//paintComponent
    public void actionPerformed(ActionEvent evt) {
    String command = evt.getActionCommand();
    if (command.equals(buttonDesc[buttonStart])) {
    startRunning();
    if (command.equals(buttonDesc[buttonQuit])) {
    stopRunning();
    if (command.equals(checkBoxDesc[checkBoxWait])){
    System.out.println("cb");
    if (checkBox[checkBoxWait].isSelected() ) {
    wait = true;
    System.out.println("cb selected twait "+wait);
    return;
    wait = false;
    synchronized(getTreeLock()) {getTreeLock().notifyAll();}
    System.out.println("cb selected fwait "+wait);
    } // end command.equal cb wait
    } //end action performed
    // A method that starts the thread unless it is already running.
    void startRunning() {
    if (running)return;
    // Create a thread that will execute run() in this Display class.
    runner = new Thread(this);
    running = true;
    runner.start();
    } //end startRunning
    void stopRunning() {running = false;System.exit(0);}
    public void run() {
    button[buttonStart].setEnabled(false);
    int x;
    x=1;
    while(x>0 && running){
    x = x + 1;
    msg[0].setText(""+x);
    try{SwingUtilities.invokeAndWait(painter);}catch(Exception e){}
    //importand dont put this in actionPerformed
    if (wait) {
    System.out.println("run "+wait);
    synchronized(getTreeLock()) {
    while(wait) {
    System.out.println("while "+wait);
    try {getTreeLock().wait();} catch(Exception e){break;}
    } //end while(wait)
    } // end sync
    } // end if(wait)
    } // endwhile(x>0)
    stopRunning();
    } // end run()
    Runnable painter = new Runnable() {
    public void run() {
    Dimension dim = msg[0].getSize();
    msg[0].paintImmediately(0,0,dim.width,dim.height);
    Thread.yield();
    }//end run in painter
    } ; //end painter
    } //end nested class Display
    } //end class Wc

    I just encountered a similar issue.  I bought a new iPhone5s and sent my iPhone4s for recycling as it was in great shape, no scratches, no breaks, perfect condition.  I expected $200 and received an email that I would only receive $24.12.  The explanation was as follows:  Phone does not power on - Power Supply Error.   Attempts to discuss don't seem to get past a customer service rep that can only "escalate" my concern.  They said I would receive a response, but by email.  After 4 days no response.  There is something seriously wrong with the technical ability of those in the recycling center.

  • Displaying a webpage in a JEditorPane from a JApplet

    Hi.
    I am trying to display a webpage in a JEditorPane from an a JApplet.
    I've tried.
    try {
            URL url = new URL("http://www.yahoo.com");
            jEditorPane1.setPage(url);
            } catch(Exception e) {e.printStackTrace();}But I got an AccessControlException:
    java.lang.RuntimeException: java.security.AccessControlException: access denied (java.net.SocketPermission www.yahoo.com:80 connect,resolve)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
         at java.net.HttpURLConnection.getResponseCode(Unknown Source)
         at javax.swing.JEditorPane.getStream(Unknown Source)
         at javax.swing.JEditorPane.setPage(Unknown Source)
         at DisplayDialog.<init>(DisplayDialog.java:21)
         at TestFrame.jButton2ActionPerformed(TestFrame.java:477)
         at TestFrame.access$200(TestFrame.java:15)
         at TestFrame$3.actionPerformed(TestFrame.java:432)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission www.yahoo.com:80 connect,resolve)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkConnect(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.<init>(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         ... 31 more
    I seem to recall something about an applet only being allowed to access pages on the same server. Is there any way to display an external webpage in a JEditorPane? Thanks.

    Unless you sign the applet's jar, you can only fetch urls from the same host as the applet was downloaded from. Part of the sandbox security restrictions.
    So go look up jarsigner for details.

  • Displaying image in JApplets which runs on Tomcat?

    hi everyone,,,
    i've JApplet including label have an image
    MyLabel.setIcon(new ImageIcon("images/java.jpeg"));the applets should runs on server - Tomcat -
    first i got error in Java Console
    <-----filepermission images/java.jpeg read----->
    and i put permission in my java.policy
    located in security folder
    after that; applet run but the image doesnot displayed on the label????
    any help please,,,
    thanx in advance

    i think the problem is with java.policy
    here is my java.policy file
    /* AUTOMATICALLY GENERATED ON Mon Feb 11 11:39:08 EET 2008*/
    /* DO NOT EDIT */
    grant codeBase "file:/usr/java/jre1.6.0_03/lib/ext/*" {
    permission java.security.AllPermission;
    permission java.io.FilePermission "<<ALL FILES>>", "read, write, execute, delete";
    grant codeBase "file:/usr/java/packages/lib/ext/*" {
    permission java.security.AllPermission;
    permission java.io.FilePermission "<<ALL FILES>>", "read, write, execute, delete";
    grant {
    permission java.io.FilePermission "images/java.jpeg", "read, write, execute";
    grant {
    permission java.io.FilePermission "java.jpeg", "read, execute, delete, write";
    };

  • JApplet Form NOT Displayed on Web Page

    It is my JApplet code (that has been solved in this forum; refer to my previous Q) that is being successfully deployed, started, however, does not display the expected GUI (which is being displayed fine if is run as an Applet).
    The error message displayed in "Java Console" is below.
    java.lang.reflect.InvocationTargetException
        at java.awt.EventQueue.invokeAndWait(Unknown Source)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder.init(XMLAnalysisToolBuilder.java:36)
        at sun.applet.AppletPanel.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.shell.Win32ShellFolder2$ComTaskExecutor
        at sun.awt.shell.Win32ShellFolder2$ComTask.execute(Unknown Source)
        at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Unknown Source)
        at sun.awt.shell.Win32ShellFolder2.composePathForCsidl(Unknown Source)
        at sun.awt.shell.Win32ShellFolder2.<init>(Unknown Source)
        at sun.awt.shell.Win32ShellFolderManager2.getDesktop(Unknown Source)
        at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
        at sun.awt.shell.ShellFolder.get(Unknown Source)
        at javax.swing.filechooser.FileSystemView.getRoots(Unknown Source)
        at javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(Unknown Source)
        at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(Unknown Source)
        at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
        at javax.swing.plaf.metal.MetalFileChooserUI.installUI(Unknown Source)
        at javax.swing.JComponent.setUI(Unknown Source)
        at javax.swing.JFileChooser.updateUI(Unknown Source)
        at javax.swing.JFileChooser.setup(Unknown Source)
        at javax.swing.JFileChooser.<init>(Unknown Source)
        at javax.swing.JFileChooser.<init>(Unknown Source)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder.initComponents(XMLAnalysisToolBuilder.java:63)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder.access$000(XMLAnalysisToolBuilder.java:30)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder$1.run(XMLAnalysisToolBuilder.java:38)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
    java.lang.reflect.InvocationTargetException
        at java.awt.EventQueue.invokeAndWait(Unknown Source)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder.init(XMLAnalysisToolBuilder.java:36)
        at sun.applet.AppletPanel.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.shell.Win32ShellFolder2$ComTaskExecutor
        at sun.awt.shell.Win32ShellFolder2$ComTask.execute(Unknown Source)
        at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Unknown Source)
        at sun.awt.shell.Win32ShellFolder2.composePathForCsidl(Unknown Source)
        at sun.awt.shell.Win32ShellFolder2.<init>(Unknown Source)
        at sun.awt.shell.Win32ShellFolderManager2.getDesktop(Unknown Source)
        at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
        at sun.awt.shell.ShellFolder.get(Unknown Source)
        at javax.swing.filechooser.FileSystemView.getRoots(Unknown Source)
        at javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(Unknown Source)
        at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(Unknown Source)
        at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
        at javax.swing.plaf.metal.MetalFileChooserUI.installUI(Unknown Source)
        at javax.swing.JComponent.setUI(Unknown Source)
        at javax.swing.JFileChooser.updateUI(Unknown Source)
        at javax.swing.JFileChooser.setup(Unknown Source)
        at javax.swing.JFileChooser.<init>(Unknown Source)
        at javax.swing.JFileChooser.<init>(Unknown Source)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder.initComponents(XMLAnalysisToolBuilder.java:63)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder.access$000(XMLAnalysisToolBuilder.java:30)
        at xmlAnalyticsPackage.XMLAnalysisToolBuilder$1.run(XMLAnalysisToolBuilder.java:38)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)Please help on this.
    Nilanjan

    May be this bug has to do with you:
    [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6544857]

  • Swing JApplet - why component in ContentPane get display in GlassPane

    I have a JApplet that contains :
    - The ContentPane have a JTable and some JButtons.
    - A JMenuBar (have actionPerformed that set up the GlassPane)
    - The GlassPane have a JTable and some JButtons.
    Here are the sequence of event :
    1. I select a button or a cell in the ContentPane
    2. I then click on the menu to activate the GlassPane. The GlassPane show up as expected
    3. But when I select any components in the GlassPane, the components that I previously
    selected in the ContentPane (in step 1) also show up.
    Why is this happening. How do I prevent the components in the ContentPane show up while I am
    displaying the GlassPane.
    Thanks

    Just an educated guess: The glass pane is transparent.
    You can make it opaque by calling setOpaque(true) on the glass pane. Check if it helps...
    Stephen

  • Problem displaying JDialog from a JApplet

    When I try to display a JDialog (of a JFrame) from a JApplet, the dialog is displayed but it never receives any paint events, so the form seems empty.
    Basically, this is what happens:
    A JPanel is added to the content pane of a JApplet.
    When that panel receives a mouse action event, a new window is created like this:
    TestWindow tw = new TestWindow();
    tw.setVisible();That's it. When the window is started from a method in the applet itself, however (init() for example) the window does display correctly.
    Can anyone tell me what might be going wrong?

    /*  <applet code="AppletDialog" width="300" height="180"></applet>
    *  use: >appletviewer AppletDialog.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class AppletDialog extends JApplet
        JDialog dialog;
        public void init()
            initDialog();
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(getNorthPanel(), "North");
            getContentPane().add(getSouthPanel(), "South");
        private void initDialog()
            JLabel label = new JLabel("dialog contents", JLabel.CENTER);
            dialog = new JDialog(new Frame(), false);
            dialog.getContentPane().add(label);
            dialog.setSize(200,100);
            dialog.setLocation(540,200);
        private JPanel getNorthPanel()
            JButton launch = new JButton("show dialog");
            launch.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    dialog.setTitle("from button");
                    dialog.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(launch);
            return panel;
        private JPanel getSouthPanel()
            JPanel panel = new JPanel(new BorderLayout());
            panel.setBackground(Color.pink);
            panel.add(new JLabel("click here for dialog", JLabel.CENTER));
            Dimension d = panel.getPreferredSize();
            d.height = 45;
            panel.setPreferredSize(d);
            panel.addMouseListener(new MouseAdapter()
                public void mousePressed(MouseEvent e)
                    dialog.setTitle("from mouse");
                    dialog.setVisible(true);
            return panel;
        public static void main(String[] args)
            JApplet applet = new AppletDialog();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(applet);
            f.setSize(300,180);
            f.setLocation(200,200);
            applet.init();
            f.setVisible(true);
    }

  • Is there a way to display a  non modal JDialog on JApplet

    Whenever I try to add a non modal JDialog over a JApplet, the JDialog freezes and components on it never gets painted. After a disappointing search over web, I've kinda begin to hate swing. I am shocked that a very basic thing like this is so hard to achieve in Java. Any solution folks?
    My code is as follows:
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    public class DialogApplet extends JApplet {
         private javax.swing.JPanel jContentPane = null;
         private JButton jButton = null;
          * This method initializes jButton     
          * @return javax.swing.JButton     
         private JButton getJButton() {
              if (jButton == null) {
                   try {
                        jButton = new JButton();
                        jButton.setText("Click Me"); 
                        jButton.setBounds(75, 80, 147, 34); 
                        jButton.addActionListener(new java.awt.event.ActionListener() {
                             public void actionPerformed(java.awt.event.ActionEvent e) {   
                                  Frame f = javax.swing.JOptionPane.getFrameForComponent(jContentPane);
                                  JDialog pi = new JDialog(f, "MainFrame Dialog", false);
                                pi.getContentPane().add(new JLabel("I got to be working Bossie!!!"));
                                pi.pack();
                                pi.setLocation(75, 80);
                                pi.setVisible(true);
                                try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                                pi.setVisible(false);
                   catch (java.lang.Throwable e) {
                        e.printStackTrace();
              return jButton;
         public static void main(String[] args) {
          * This is the default constructor
         public DialogApplet() {
              super();
              init();
          * This method initializes this
          * @return void
         public void init() {
              this.setSize(300,200);
              this.setContentPane(getJContentPane());
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private javax.swing.JPanel getJContentPane() {
              if(jContentPane == null) {
                   jContentPane = new javax.swing.JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJButton(), null); 
              return jContentPane;
    }

    try this, it is really simple, just to look at
    example from the swing tutorials.
    Thanks my friend, If you carefully observe my code, I also needed some piece of code to run in the background ((The thread.sleep() part)) while displaying the dialog. The problem was the JDialog used to freeze and components on it never used to get painted. Finally I managed to find a way out. If we try to display a JDialog with a new thread, The event dispatching thread takes precedence and the painting of components on the JDialog happens only after even dispatching thread is done. All I did was display JDialog in the event dispatch thread and run the background process in new thread.
    My code.
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class DialogApplet extends JApplet {
        private javax.swing.JPanel jContentPane = null;
        private JButton jButton = null;
        private JDialog dialog = null;
         * This is the default constructor
        public DialogApplet() {
            super();
            init();
         * This method initializes this
        public void init() {
            this.setSize(300, 200);
            Container container = this.getContentPane();
            container.add(getJContentPane());
         * This method initializes jContentPane
         * @return javax.swing.JPanel
        private javax.swing.JPanel getJContentPane() {
            if (jContentPane == null) {
                jContentPane = new javax.swing.JPanel();
                jContentPane.setLayout(null);
                jContentPane.add(getJButton(), null);
            return jContentPane;
         * This method initializes jButton
         * @return javax.swing.JButton
        private JButton getJButton() {
            if (jButton == null) {
                try {
                    jButton = new JButton();
                    jButton.setText("Click Me");
                    jButton.setBounds(75, 80, 147, 34);
                    jButton.addActionListener(new java.awt.event.ActionListener() {
                            public void actionPerformed(java.awt.event.ActionEvent e) {
                                showDialog();
                } catch (java.lang.Throwable e) {
                    e.printStackTrace();
            return jButton;
         * This method displays Dialog
        public void showDialog() {
            final Frame frame = JOptionPane.getFrameForComponent(this);
            dialog = new JDialog(frame, "DialogApplet", false);
            dialog.setModal(true);
            Container contentPane = dialog.getContentPane();
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JLabel("I got to be working Bossie!!!"), BorderLayout.CENTER);
            contentPane.add(panel);
            dialog.pack();
            Thread t = new Thread() {
                    public void run() {
                        for (int i = 0; i < 100000; ++i) {
                            System.out.println(i);
                        dialog.hide();
            t.start();
            dialog.show();
    }

  • Fillrect to display multiple times on japplet - help!

    I am really having a hard time getting my program to work. The requirement is for a user to input the four requirements or parameters of the drawRect method class and to draw multiple rectangles in different coordinates on the screen.
    I have my code, it is working, but it is not putting the rectangles on different areas on the screen. It seems like it is not moving the coordinates when it goes through the loop.
    Here it is:
    import javax.swing.*;
    import java.awt.Graphics;
    public class fillRect extends JApplet {
    int num1, num2, num3;
    int num4, num5, num6;
    int num7, num8, num9;
    int num10, num11, num12;
    int num13, num14, num15, num16;
    int num17, num18, num19, num20;
    public void init()
    String input;
    int Xl, Yl, Width, Height;
    for ( int i = 1; i <= 1; i++ )
    String inputString; //string entered by the user
    //read from user as a string,
    //and convert type String to type int
    inputString = JOptionPane.showInputDialog("Please enter the upper left X-coordinate value:");
    Xl=Integer.parseInt( inputString );
    inputString = JOptionPane.showInputDialog("Please enter the upper left y-coordinate value:");
    Yl=Integer.parseInt( inputString );
    inputString = JOptionPane.showInputDialog("Please enter the width (non-negative):");
    Width = Integer.parseInt( inputString);
    inputString = JOptionPane.showInputDialog("Please enter the height (non-negative):");
    Height = Integer.parseInt( inputString );
    if ( Xl >= 1 && Yl <= 100 && Height <= 100 && Width <= 100 )
    switch ( i ) {
    case 1:
    num1 = Xl;
    num2 = Yl;
    num3 = Width;
    num4 = Height;
    break;
    case 2:
    num5 = Xl;
    num6 = Yl;
    num7 = Width;
    num8 = Height;
    break;
    case 3:
    num9 = Xl;
    num10 = Yl;
    num11 = Width;
    num12 = Height;
    break;
    case 4:
    num13 = Xl;
    num14 = Yl;
    num15 = Width;
    num16 = Height;
    break;
    case 5:
    num17 = Xl;
    num18 = Yl;
    num19 = Width;
    num20 = Height;
    break;
    else
    JOptionPane.showMessageDialog ( null, "Must be between 1 and 1000", "Error", JOptionPane.ERROR_MESSAGE );
    public void paint ( Graphics g) {
    int x, y = 0, value = 0, value1 = 0, value2 = 0, value3 = 0;
    for ( int i = 1; i <= 1; i++ ) {
    x = 5;
    switch ( i ) {
    case 1:
    value = num1;
    y = 50;
    value2 = num3;
    value3 = num4;
    break;
    case 2:
    value = num5;
    y = 60;
    value2 = num7;
    value3 = num8;
    break;
    case 3:
    value = num9;
    y = 70;
    value2 = num11;
    value3 = num12;
    break;
    case 4:
    value = num13;
    y = 80;
    value2 = num15;
    value3 = num16;
    break;
    case 5:
    value = num17;
    y = 90;
    value2 = num19;
    value3 = num20;
    break;
    for ( int j = 1; j <= value2; j++ )
    g.fillRect ( value *= 10, y, value2 *= 10, value3 *= 10 );
    }

    Hi,
    Maybe the code below can help you out.
    import javax.swing.*;
    import java.awt.*;
    //import java.text.*;
        <APPLET CODE="fillRect" WIDTH=600 HEIGHT=400></APPLET>
    public class fillRect extends JApplet
      private final int NUM_RECTS = 4;
      private int rectWidth, rectHeight, rectX, rectY;
      private int getInput( String prompt, int lowValid, int highValid )
        int outVal = Integer.MIN_VALUE;
        boolean valid = false;
        while( !valid )
          String inputString = JOptionPane.showInputDialog( prompt );
          try
            outVal = Integer.parseInt( inputString );
            if( outVal >= lowValid && outVal <= highValid )
              valid = true;
            else
              throw new NumberFormatException();
          catch( NumberFormatException nfee )
            JOptionPane.showMessageDialog( null, "Invalid: Must be between " +
                                           lowValid + " and " + highValid + ".",
                                           "Error", JOptionPane.ERROR_MESSAGE );
        return( outVal );
      public void init()
        // Get inputs from user.
        rectX = getInput( "Please enter the upper left X-coordinate value:",
                          1, Integer.MAX_VALUE );
        rectY = getInput( "Please enter the upper left y-coordinate value:",
                          1, Integer.MAX_VALUE );
        rectWidth = getInput( "Please enter the width (non-negative):", 1, 100 );
        rectHeight = getInput( "Please enter the height (non-negative):", 1, 100 );
      public void paint( Graphics g)
        if( rectX > 1 )
          Dimension dim = getSize();
          g.setColor( Color.cyan );
          g.fillRect( rectX, rectY, rectWidth, rectHeight );
          for( int j = 1; j < NUM_RECTS; ++j )
            int offsetX = (int)(Math.random() * (dim.width - rectWidth));
            int offsetY = (int)(Math.random() * (dim.height - rectHeight));
            g.fillRect( rectX+offsetX, rectY+offsetY, rectWidth, rectHeight );
    }Regards,
    Manfred.

  • Displaying message  in JApplet while downloading a file

    hi
    In my applet Im trying to download a file from server to client while downloading i want display progressbar/ msg
    when i try to do this my applet GUI dosnot loads untill that file download complete and i tried with a button so that ofter clicking on it download should start, in this case also the masg doesnot changes according to given setText method for that Jlabel.while output message to console is printing properly.
    even i have tried with generating new thread to set Jlabel text message. that also doesnot worked
    here im going to paste my code part of applet could anybody tell me what wrong in my code / else what could be done..?
    client machine is windows XP
    public void init()
    Container Contentpane=getContentPane();
    Contentpane.setLayout(null);
    textpanel = new JPanel();
    textpanel.setLayout(null);
    textpanel.setBounds(10,40,250,200);
    msg=new JLabel();
    msg.setBounds(5,5,200,150);
    textpanel.add(msg);
    getContentPane().add(textpanel);
    public void start()
    msg.setText("<html>Downloading File to System...<html>");
    URL inFileURL=new URL(getCodeBase()+"/load/My.dll");
    System.out.println(" opening connection- ");
    URLConnection urlfl=inFileURL.openConnection();
    urlfl.setDoInput(true);
    urlfl.setDoOutput(true);
    urlfl.setUseCaches(false);
    urlfl.setRequestProperty("Content-Type", "application/octet-stream");
    int sz=urlfl.getContentLength();
    System.out.println(" Total Length ... " +sz);
    BufferedInputStream inFile1 = new BufferedInputStream (urlfl.getInputStream(),urlfl.getContentLength());
    int succesbytes = 0;
    int current_read;
    byte[] strMsg11 = new byte[urlfl.getContentLength()];
    int readrs;
    BufferedOutputStream outfl =new BufferedOutputStream(new FileOutputStream("c:\\My.dll"));
    while(inFile1.available() > 0)
    current_read =inFile1.read(strMsg11,0,urlfl.getContentLength());
    System.out.println(" Current Read = "+current_read);
    succesbytes += current_read;
    outfl.write(strMsg11,0,current_read);
    msg.setText("<html>"+successbytes+" bytes downloaded successfully..<html>");
    System.out.println("Written ... = " +succesbytes );
    outfl.flush();
    outfl.close();
    } //end of start
    thanks in advance
    Edited by: Hegde on Oct 6, 2007 6:48 AM

    Hi Vic,
    Please post in ASP.NET forums.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Swing components not displaying correctly in JApplet

    Hello everyone,
    I have experienced some strange problems using Swing components on JApplets. Maybe I missed some documentation somewhere and someone can help me out.
    The problem is that when I add components like JButtons,
    JCheckboxes, JRadioButtons, JTextFields, JPasswordFields,
    and JComboBoxes to JApplets, when I view the applet, the
    component does not become visible until I move the mouse
    pointer over it in the case of buttons. For the JComboBox I have
    to hit the mouse key many times on the component to see the list. Has anyone experienced problems like these? Thanks.
    Keith

    check what is in ur paint(Graphic g) method. if it does nothing, remove the paint(Graphic g) method. if it has some codes, double check ur codes.

  • JApplet cannot display JTooltip at right location !!!!!!!!

    I am using ATI 9200 graphic card with Hydravision, and connect two Dell 19 inchs LCD monitors to it. The applet was displayed on the secondary monitor. But the problem is that all the tooltips for textfields in the applet were displayed on the primary monitor.
    there is more problem with Hydravision. All of dialog boxes are displayed on the primary monitor while the applet is on the secondary monitor.
    I have set Hydravision's dialog control setting to "show on app's monitor", however it is still not working correctly.
    I just don't know if anybody else has this kind of problem when you are working
    with two monitors system.
    Thank you

    Hello Daniel,
    I do know that the Full Screen option is a QuickTime Pro-only feature if you play it in QuickTime. However, you should be able to play it in Full Screen under iTunes without the Pro version of QuickTime by going in the iTunes Preferences --> Playback --> Play videos: full screen.
    As with the other sizes, I'm not quite sure the reason they're greyed out; You can do Half and Double with regular QuickTime.

  • Display data in JTable

    I am trying to display data from database into the JTable swing component. I can see the table and the heading coming from the vector. I cannot see why the data from the databse table is not loaded on to the Jtable. I just get a table with 6 rows blank.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class dataTable extends JApplet
    String dbdriver="jdbc:oracle:thin:@ds1.ctateu.edu:1521:wpac";
    String dbuser="system";
    String dbpass="pass";
    Container c;
    JScrollPane jsp;
    JTable table;
    int v,h;
    Connection connection;
    Statement stmt;
    ResultSet rs;
    String param_start,param_end, param_disp_start, param_disp_end,param_shortdesc, param_longdesc;
    public void init()
    c= getContentPane();
    c.setLayout (new BorderLayout());
    v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
    h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
    Vector heading = new Vector();
    heading.addElement("Event Start Date");
    heading.addElement("Event End Date");
    heading.addElement("Display Start Date");
    heading.addElement("Display End Date");
    heading.addElement("Short Description");
    heading.addElement("Long Description");
    Vector data = new Vector();
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    connection=DriverManager.getConnection(dbdriver,dbuser,dbpass);
    stmt=connection.createStatement();
    rs= stmt.executeQuery("select * from univevents");
    while(rs.next())
    param_start = rs.getString("start_date");
    param_end = rs.getString("end_date");
    param_disp_start = rs.getString("display_start");
    param_disp_end =rs.getString("display_end");
    param_shortdesc = rs.getString("short_desc");
    param_longdesc = rs.getString("long_desc");
    catch (Exception e)
    //JOptionPane.showMessageDialogue("Exception: "+e.getMessage());
    data.addElement(param_start);
    data.addElement(param_end);
    data.addElement(param_disp_start);
    data.addElement(param_disp_end);
    data.addElement(param_shortdesc);
    data.addElement(param_longdesc);
    table = new JTable(data, heading);
    jsp = new JScrollPane(table,v,h);
    //Add scrollpane to container
    c.add("Center",jsp);
    }//init
    }//JApplet

    Your data vector should be a Vector of Vectors.
    I think you need to change your loop to look something like this:
    while(rs.next())
        Vector row = new Vector();
        row.addElement( rs.getString("start_date") );
        row.addElement( rs.getString("end_date") );
        row.addElement( rs.getString("display_start") );
        row.addElement( rs.getString("display_end") );
        row.addElement( rs.getString("short_desc") );
        row.addElement( rs.getString("long_desc") );
        data.addElement( row );
    } Then remove your data.addElement() statements found outside the loop.

Maybe you are looking for

  • How can I order a custom size photo from iphoto?

    Hi, I have three frames that I want to order photos for from iphoto.  The custom size is 5 x 5 which is no problem selecting from within iPhoto, but when it comes time to actually place the "order", there is no option to select a 5 x 5 size.  Can any

  • Out of sync audio - CC 7.2.2

    Hi I'm quite a newbie in editing. Again a problem with audio synchronization. Last time I had to make a DVD and it was resolved simply with Encore, as a kind person here told me. This time, my sequence settings: - avchd 1080p square pixel, 25 fps. -

  • ABAP STACK and JAVA STACK certificates

    Hi Fiends, I have requirement in which I want to use HTTP adapter to send message and apply security certificate. I got from sdn that if I wan to use http adapter with certificate than I have to install certificates in ABAP stack. My problem is I had

  • IPhoto '09 Facebook upload problem

    I have been uploading photos using iPhoto '09 to my Facebook account for years.  Just a couple of days ago I started receiving a message box "Do you want to set up iPhoto to publish to Facebook?" when I click on the Facebook icon.  If I go ahead with

  • Help!! Iphone 3 restore needed!! - keeping data

    HELP!!!!  my iphone 3 is displaying a msg saying "restore needed" i have no signal from a network (which i have already spoken to them about) and iphone tells me to plug into itunes. When i plug it in, my computer asks me to unlock my phone, i am una