Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Is a modal JDialog possible in this scenario?

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is a modal JDialog possible in this scenario?

    I have the below spinet of code which basically consists of a panel with a progress bar. The progress bar indicates the completion rate for the numerical computations executed in RunComputations(). It takes several seconds for the computations to be completed. RunComputations is called after an instance has been created.

    I would like this this panel (basin) to be modal but I can't. JVM stops at dialog.setVisible(true) and waits for an action on behalf of the user. Is there anyway to have a modal panel in these circumstances?

    *********************
    //this code invokes Basin Panel

    Basin basin = new Basin(); //JVM does not proceed after this point.
    basin.RunComputations();


    //Basin panel is called by the above code

    public class Basin extends javax.swing.JPanel {
    private JDialog dialog;

    Basin(){

    dialog = new JDialog(fr,"Running Model...",true);
    dialog.add(this);
    dialog.setSize(430,130);
    dialog.setModalityType(ModalityType.APPLICATION_MO DAL); //If MODELESS is used here my program works as expected
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ ON_CLOSE);
    dialog.setVisible(true); //JVM stops here.

    }

    void RunComputations(){
    //Computations are run and progress bar is updated
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Is a modal JDialog possible in this scenario?

    The definition of modal is (roughly): takes and keeps program focus until the user supplies information or cancels the dialog. So what you've described you want conflicts with what is. Maybe I don't understand what you said.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is a modal JDialog possible in this scenario?

    Thanks for your response. Are there any approaches? I would like to keep the panel modal (inside JDialog) while the computations are performed and the progress bar is updated. As far as I know java does not offer any other alternative for a modal panel.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Is a modal JDialog possible in this scenario?

    Are you trying to have two separate parts of the program execute at the same time? Using Threads would help you do that.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Is a modal JDialog possible in this scenario?

    But in a Swing application, use SwingWorker.

Similar Threads

  1. Need some help with this JFrame, or JDialog.
    By MR bruto in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 10th, 2013, 08:14 AM
  2. Identifying OO elements in this scenario
    By vinayjava in forum Object Oriented Programming
    Replies: 6
    Last Post: December 26th, 2012, 04:00 AM
  3. suggestionbox inside modal panel
    By smackdown90 in forum Web Frameworks
    Replies: 1
    Last Post: April 8th, 2010, 01:16 PM
  4. Facing problem with open modeless dialog from modal window
    By Divya in forum Java Theory & Questions
    Replies: 1
    Last Post: May 14th, 2009, 03:18 AM