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 3 of 3

Thread: ProgressMonitorInputStream never pops up

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ProgressMonitorInputStream never pops up

    I've been banging my head against a wall for almost 3 hours now, trying to get a progress monitor to open up while I load a big file. Here is my code:

        public static void main(String[] args) {
            AttTest testit = new AttTest();
            testit.runAttTest();
        }
     
        public void runAttTest() {
            String fname = "C:/test.model";
            Vector<Object> test = new Vector<Object>();
            try {
                  ObjectInputStream  input =
                    new ObjectInputStream
                      (new ProgressMonitorInputStream(null, "Loading",
                                                      new FileInputStream(fname)));
                  while (true) {
                      test.add(input.readObject());
                  }
                input.close();
            } catch (Exception ex) {
                System.err.println("Deserialization failed: " + ex.getMessage());
                ex.printStackTrace();
     
            }
       }

    The file is big - takes over 5 minutes to load. It loads fine, but the progress monitor never pops up. Can anyone tell me what I'm doing wrong here? Thanks for the help!

    Best regards,

    Michael


  2. #2
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ProgressMonitorInputStream never pops up

    Maybe all that headbanging knocked something loose yesterday. Anyway, the code DOES work - just not when you're running in Debug mode (I'm using Netbeans). Running normally, the window pops up. It's blank, but at least it pops up. If anyone has any suggestions on why it's blank, I'd love to hear them...

    Thanks.

    Michael

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,330
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: ProgressMonitorInputStream never pops up

    I've never used ProgressMonitorInputStream, but usually when working with long tasks and showing updates in a GUI during that task, the long tasks should be performed in a separate thread and updates to the GUI called onto the GUI thread. See:
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)