Unable to open JDialog from swing application when run from Applet

Posted on 2011-10-20
Medium Priority
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
  • 2
LVL 47

Expert Comment

ID: 37004154
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

Pramod Kumar earned 375 total points
ID: 37004884
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

ID: 37036312
OK it works

Author Closing Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 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