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: Running the try before printing something?

  1. #1
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Running the try before printing something?

    I was wondering something.
    I have a subclass thas has:

    public void OpenReadFileOne() {
    		// Open JFileChooser. 
    		chooser1.showOpenDialog(null); 
    		// Give the user a notification that the program is busy ready file1 in. 
    		label1.setText(" Reading in a file, plz wait.");
    		label1.setForeground(Color.MAGENTA);
    		// Get the selected file. 
    		java.io.File file1 = chooser1.getSelectedFile();
    		// Create a FileInputStream. 
    		FileInputStream fileInput1 = null; 
    		//Get the name of the selected file, and print it on the GUI screen. 
    		fileName1= file1.getName();
     
    		// Create a FileInputStream that will be used to read excel files. 
    		try {

    Now I have a try catch inserted in there too.
    As you can see where the try { starts.

    Now the plan is to get the text " Reading in a file, plz wait." printed on the GUI.
    And then the program is busy with reading in file1 and processing it.
    And last he prints out: "File selected: "

    finally {
    			// Show the user the name of the selected file that was loaded in.
    			label1.setText(" File selected: " + fileName1); 
    			label1.setForeground(Color.BLUE);
    		}

    But it doesn't print the " Reading in a file, plz wait." on the GUI.
    But it does print the " File selected: ".

    So I am thinking he is running the try first before he puts something on the GUI screen.
    While that is not suppose to be happening...

    Does anybody maybe know why?
    Becasue I did put the text " Reading in a file, plz wait." above the try {


  2. #2
    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: Running the try before printing something?

    Not sure where and how the small sections of code that are posted are executed. If only the last text if being shown it could be because your code is holding the GUI's thread(EDT) and not letting the GUI thread update what is being shown until your code finishes.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Running the try before printing something?

    I will have a look for that one.

Similar Threads

  1. KeyEvent Running Twice?
    By JuLiAnc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2012, 04:43 PM
  2. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  3. Printing Job
    By qwerty53 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 19th, 2011, 08:34 AM
  4. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM
  5. Replies: 1
    Last Post: March 3rd, 2009, 08:04 AM