?
Solved

Unable to open JDialog from swing application when run from Applet

Posted on 2011-10-20
4
Medium Priority
?
463 Views
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
{
 init()
{
 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?
0
Comment
Question by:harishalwala
  • 2
4 Comments
 
LVL 47

Expert Comment

by:for_yan
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.
0
 
LVL 10

Accepted Solution

by:
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");
    b.addActionListener(this);
    add(b);
  }

  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"));
      d.pack();
      d.setLocation(300,100);
      d.show();
    }
  } 
}

Open in new window

0
 

Author Comment

by:harishalwala
ID: 37036312
OK it works
0
 

Author Closing Comment

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

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