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();
}

Similar Messages

  • Is there a way to display multiple iPad screens on the same television screen simultaneously?

    Is there a way to display multiple iPad screens on the same television set concurrently?  The idea is to let multiple individuals do something on their iPads in a timed window and then display the results of each iPad users answer concurrently on te same television.

    Devices that display two, four, or even eight video signals on a single monitor are available in the video security market. Maybe you could find something there that would do what you want. A quick search on "security tv screen multiplexor" (without the quotes) yielded millions of pages; several on the first page looked promising if you don't mind composite video.

  • Is there a way to display the date and time on my officejet 6500

    HP Officejet 6500a Plus Windows XP_ Is there a way to display the date and time on the display of my printer

    Are you referring to the Date and Time some cameras put right on the image?  If so there is nothing really good in iPhoto to do this. You could try the Retouch tool and see how that looks but I think you will need something more precise and powerful, like the clone tool in Aperture.
    Also something like PhotoShop or GIMP - The GNU Image Manipulation Program (free) should do what you want also.
    If your asking about some other date post back.
    regards

  • Is there a way of displaying  the various item in my Downloads folder as icons arranged in order of Date Created, such that the most recent items appear at the bottom, rather than the top?

    Is there a way of displaying  the various item in my Downloads folder as icons arranged in order of Date Created, such that the most recent items appear at the bottom, rather than the top? I know this can be done when they are displayed as a list, but I want icons!

    Hi geezer,
    when you open your 'Downloads' folder choose 'View'  in the Menu bar and choose:
    'as List'
    'Show View Options'
    In 'View options' window you tick:
    'Always open in list view'
    'Date Modified', or
    'Date created'
    Now inside the 'Downloads' folder click on 'Date Created' (or 'Date Modified')
    column to get items alined from oldest to newest date (or reverse)…

  • Is there any way to display filenames or captions for photos?

    is there any way to display filenames or captions for photos?

    Thanks. There are so many it's very hard to see which one does what. Since I edit  on the MacBook Pro using Photoshop Elements, all I really need is a way of seeing the filenames, and secondarily re-arranging thumbnails on the iPad screen manually.

  • Is there any way to display pictures in a report program...

    Is there a way to display some pictures say background or foreground pics in a report program ??
    Kindly help me in this.
    Thanks in advance,
    Krishna,
    9986023724

    Hi Krishna,
    Go througth the following document.
    <a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIIMAGE/BCCIIMAGE.pdf">http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIIMAGE/BCCIIMAGE.pdf</a>
    Regards,
    sukhee

  • I want ro remove all of the default Firefox bookmarks. There are way too many and none of which are usefull to me. I would like to make my old IE Favorites folder the default. How can I do this?

    I need to remove the default Firefox bookmarks.
    There are way too many and none of which are usefull to me.
    Also, I am vision impaired and reading through such a long list is very eye-fatigueing to me.
    I would like to make my old IE Favorites folder the default. How can I do this?

    Did you import an iPhoto Library from the old Hard Drive? Do you still have that old Library?
    The way to clear out a Library is to Export the photos - Apps like iPhoto2Disk or PhotoShare will help you export to a Folder tree matching your Events.
    For the annoying start-up message:
    Go to your Pictures Folder and find the iPhoto Library there. Right (or Control-) Click on the icon and select 'Show Package Contents'. A finder window will open with the Library exposed.
    Look there for a Folder called 'Import' or 'Importing'.
    Drag it to the Desktop. *Make no other changes*.
    Start iPhoto. Does that help?
    If it does then look inside that folder on your desktop. Does it contain anything you want? If not you can trash the folder.

  • Is there any way to display JTree without using applet

    Hi,
    is there any way to display JTree without using applet . Can we display the JTree in a JSP page.
    With Regards,
    Sheema.

    Not a JTree, per se. But there are Javascript solutions out there and there are JSP tag library solutions which use a JTree on the server side to hold and maintain the data and expanded nodes.
    This is one that I've used before, it's pretty good:
    http://www.jenkov.dk/treetag/introduction.tmpl

  • Is there a way to display the coordinates(x,y)  of the objects automatically ?

    hi and happy new year
    is there a way to display the coordinates(x,y)  of the objects automatically (may be on a label over the object ) and print them?
    i mean i want to design a game level (in pixels) place the object on the map ang get the locations automatically to print them
    thank you
    txarly

    Good day!
    Which version of Photoshop do you use?
    If you have CS6 Etended the Measurement Log might provide some options to store and print the information separately, but if I interpret your wuestion correctly (for example that by »object« you mean »Layer«) I think a Scripting approach would be best.
    Scripts can be used to automate tasks with more options regarding conditionality than Actions by using JavaScript-, VB- or ApplaScript-code to control Photoshop.
    If you want to pursue that option you could ask for help over at
    http://forums.adobe.com/community/photoshop/photoshop_scripting
    or
    http://ps-scripts.com/bb/
    But please post screenshots/mock-ups right away to illustrate what you start with and what result you want.
    Regards,
    Pfaffenbichler

  • Is there a way to display the time-code of all tracks?

    I bumped some audio out of sync.  Is there a way to display all my audio and video time-codes simultaneously, so that I can see if my tracks are out of sync, and by how much?

    You could link video and audio tracks in the timeline
    that you want to stay in sync with each other.
    Link or unlink video and audio
    Once video and audio clips are linked in the timeline, you can
    view the offset in frames if you happen to accidentally slip the sync.
    There are a couple of automatic methods for recovering lost sync in
    linked clips.
    Automatically synchronize clips that were moved out of sync

  • Is there a way to display the song timing/duration?

    I have a new 6th generation iPod Nano. Is there a way to display the song timing? Sometimes I want to fast forward to right at the end. I guess I miss the click wheel when I could zoom right to the end without just holding down the arrow and guessing about when I'd get there. Is there a way to access this function on the new nanos?

    You're welcome. You can find the manual for the 6th Generation Nano here: http://manuals.info.apple.com/enUS/iPod_nano_6thgen_UserGuide.pdf

  • Is there a way to display log notes in the timeline?

    Hi All,
    Is there a way to display log notes in the timeline?
    My assistant has put all the vital information into the log notes instead of the name column...not a biggie but just so used to seeing a description on the timeline rather than a tape number.
    Thanks,
    Susan.

    Hi G,
    Thanks! But I want to display the info permanently in the timeline. Like ---- sorry ---- in the Avid, I can change the timeline to be blank or display other info like mediafile names, etc, etc. I've looked in the Sequence Settings and it looks like I can only change the clip display in the TL to be with frames or without frames. Any help would be greatly appreciate...thanks!
    Cheers,
    Susan.

  • Change a modal JDialog to non-modal JDialog

    I created a modal JDialog initially, for some result i need change it to a non-modal JDialog, is there any set modal command can do it??

    Nope.
    The reason is because of program flow:
    System.out.println("first line");
    JDialog dialog = new JDialog(modal);
    dialog.setVisible(true); // blocks this flow if and only if modal is true
    System.out.println("second line");
    Try putting a button in the dialog which prints out "button pressed".
    If you press the button each time before closing the dialog you will get:
    when modal is true:
    first line
    button presed
    second line
    when modal is false:
    first line
    second line
    button prese

  • JButton on XP non-modal Jdialog doen't work.

    I recently upgraded from 1.3 to 1.4 while upgrading my OS from NT 4.0 to XP.
    In a stand-alone application I have non-modal JDialog's that are launched as threads so that I can have multiple instances of them running simultaneously. There are JButton's on the JDialog's which no longer respond to any mouse events even though I can execute them via the keyboard using the tab and enter keys. They work just fine under 1.3 or if I make them modal.
    Any thoughts?

    Hello,
    Issue is-
    There are JButton's on the JDialog's which no longer respond to any mouse events even though I can execute them via the keyboard using the tab and enter keys. They work just fine if I make them modal.
    Plz suggest

  • Non modal JDialog

    Hi All,
    I want a non modal JDialog which is used to show the message to the user that it is searching for the records, when a search is performed and records are retrieved from the database. When the search is going on user might hit cancel on the JDialog to cancel the search. My problem is, the cancel button on the Search dialog is not catching the event and user is not able to select the cancel option on the dialog.
    Here is my code :
    class SearchWindow extends JDialog {
    private JPanel btnPanel;
    private JLabel lblSearch;
    private JButton btnCancel;
    * Constructor
    public SearchWindow() {
    super((Frame)null, false);
    setTitle("Searching Shipment Legs");
    cancelled = false;
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent evt) {
    close();
    Container contentPane = getContentPane();
    contentPane.setLayout(null);
    addButtons();
    pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(new Dimension(300, 100));
    setSize(300,100);
    setLocation((screenSize.width-700)/2,(screenSize.height-450)/2);
    private void addButtons() {
    btnPanel = new JPanel();
    btnPanel.setLayout(new BorderLayout());
    lblSearch = new JLabel("Searching..........");
    btnCancel = new JButton("Cancel");
    btnPanel.setBackground(Color.lightGray);
    lblSearch.setBackground(Color.lightGray);
    btnCancel.setBackground(Color.lightGray);
    btnPanel.add(lblSearch, BorderLayout.CENTER);
    btnPanel.add(btnCancel, BorderLayout.SOUTH);
    btnCancel.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent evt) {
    System.out.println("cancel");
    cancelled = true;
    close();
    btnPanel.setBounds(0,0,200,50);
    this.getContentPane().add(btnPanel);
    lblSearch.setVisible(true);
    btnCancel.setVisible(true);
    this.getContentPane().validate();
    public void close() {
    this.setVisible(false);
    this.dispose();
    public void show() {
    super.show();
    paintComponents(getGraphics());
    this.setModal(false);
    Any help is greatly appreciated.
    Thanks,
    Bhaskar

    Hi Haroldsmith
    I am calling this search window in one of my programs where on button click it will fetch the records from the database. When this process is on, search dialog is shown up. Ths dialog is shown correctly and its getting closed as soon as the search is completed. But the probelm is its not allowing me to click on cancel button.
    Bhaskar

Maybe you are looking for

  • Unkown failure when submitting a form to PHP web page

    Hello. I've been having a following issue when using Adobe Reader X version 10.1.3.23 and the newest version. An error occurred during submit process. Unkown failure. This happens when the document is receiving data from web page. Following javascrip

  • Collected Tooltip does not display in SSRS 2008 or SSRS 2008 R2 on a pie chart

    I've tried everything I can think of, but setting the Custom Property "Collected Tooltip" for a pie chart where there is data that will be "collected" into an "Other" slice doesn't appear to work.  I am using SQL Server 2008 and SQL Server 2008 R2, a

  • Multiple plants to be assigned/linked to one material number

    Hi,  I have a list of materials which are available in one perticular plant. I want to create/extend/link them in couple of other plants as well. Is there any way i can do all of them at  once. (something like mass update/create/change) I did try in

  • Power Problem?

    I have an iMac (20") that I bought in Nov. 2004. I have never had any problems until recently. I upgraded to Leopard (from Panther) and went to 2 GB RAM in order to use Adobe CS3. Prior to installing Photoshop I experienced the power shut off that se

  • Sdo_geom

    HI I am working with Oracle 11.2.0.1.0. The following query gives incorrect result. There are two geometries, they are DISJOINT but the query says that it is INSIDE select sdo_geom.relate(a.geometry, 'determine', b.geometry, 0.05) from test a, test b