Unable to open JDialog from swing application when run from Applet

Posted on 2011-10-20
Last Modified: 2013-11-23
I have created a swing application, which runs fine when I run from desktop. The same application is now run from Applet.
class abc extends JApplet
 new Main()

Main class extends JFrame, it has JDialog opens for Login.
Now my problem is When I run Applet login dialog does not open up. I dont see any error in Applet console.

Any Thoughts?
Question by:harishalwala
    LVL 47

    Expert Comment

    That may be due to some limitationm with the browser to open new windows - like pop-up blocking or something like that

    Try in another browser.
    LVL 10

    Accepted Solution

    Try this:

    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.*;
    public class Login extends JApplet implements ActionListener
        JButton b;
      private Frame findParentFrame(){
        Container c = this;
        while(c != null){
          if (c instanceof Frame)
            return (Frame)c;
          c = c.getParent();
        return (Frame)null;
      public void init(){
        setLayout(new FlowLayout());
        b = new JButton("push me");
      public void actionPerformed(ActionEvent e){
        Frame f = findParentFrame();
        if(f != null){
          JDialog d = new JDialog(f, "modalDialog", true);
          d.setLayout(new FlowLayout());
          d.add(new Label("hello"));

    Open in new window


    Author Comment

    OK it works

    Author Closing Comment

    I got the way for finding solution, though this is not the actual solution I am looking for

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    755 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

    26 Experts available now in Live!

    Get 1:1 Help Now