• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble with Java 7 on a mac

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been programming in java for a bit now and can generally figure out things. But this one has me stumped. I have a mac and I have recently updated from java 6 to java 7. I had quite a bit of code that was running fine with java 6, but is having problems in java 7. The precise problem is that only the first JFileChooser dialog window in the program will actually show up (the window to select the files). I include a snippet of code below:



Only the open dialog window of chooser1 will show up. The dialog window for chooser2 never shows up. The program acts like the chooser2.show OpenDialog statement is executing and is waiting for me to select a file, but nothing shows up.

As I said code like this (several JOptionChooser dialogs or JOptionPane dialog in a row) ran with no problem before the upgrade to java 7. Now only the first one show up. ??? help!
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

I can't reproduce the issue on my Windows / Java 7 box. Are you sure you're running this code on the Event Dispatch thread?
 
cate anderson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Martin,
Thank you for your time to reply, but as I said, I am working on a MAC which has "special" issues.
As far as an event dispatch thread,... well let me put it this way. If you cut and paste the above code into the
main method of a new class and then compile and run, you should get two file chooser dialog window in a row.
Nothing exotic, nothing more than a novice program would do.

I believe this is a Mac issue and I hope there are others out there (mac users) that might have had the same problem.
Java 7 is the first non-apple version of java available from oracle. As such, there are bugs!! This is the reason that
questions to uninstall java 7 on macs are such popular topics!!

I teach java and and a few of my students that were mac users and upgraded also had this problem. Their solution was to
go back to java 6. I hope to solve this and move on.

 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

cate anderson wrote:As far as an event dispatch thread,... well let me put it this way. If you cut and paste the above code into the
main method of a new class and then compile and run, you should get two file chooser dialog window in a row.
Nothing exotic, nothing more than a novice program would do.


Yes, I can put that code into my main method and it works in my environment. Nevertheless, I wouldn't be so benevolent about it. Swing has a clearly documented requirement that all Swing code must be run on the Event Dispatch thread, and teaching students otherwise is very, very bad, in my opinion. It might work somewhere, but it isn't guaranteed to work. Such code is faulty.

If you take your example, run it on the EDT and it doesn't behave as you expect, then yes, that would mean Java on your platform has problems. I'd suggest to try it (I can't do it myself, not having a Mac) and if it doesn't work, to file a bug with Oracle.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:If you take your example, run it on the EDT and it doesn't behave as you expect, then yes, that would mean Java on your platform has problems. I'd suggest to try it (I can't do it myself, not having a Mac) and if it doesn't work, to file a bug with Oracle.



Emphasis on running it within the Event Dispatch thread - don't file a bug report otherwise.

For what it's worth, running it within Eclipse Kepler (20130919-0819) on my Mac Mountain Lion 10.8.5 (Kernel Version 12.5.0) resulted in the same results you saw.

Running it from the command line Java (build 1.6.0_65-b14-462-11M4609) resulted in both dialogs being displayed and both selected files being output:

FileName 1:BeerSong.javaFileName 2:AudioHijack.mp3h105:bin andrew$
FileName 1:checkConnectTime.shFileName 2:BeerSong.javah105:bin andrew$

(the h105 is my machine name, bin is the directory I was in, andrew is my login name).
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just went back and checked - I have configured Eclipse to use Java 1.7.0_11.

Bumping it back to 1.6 made it work correctly in Eclipse.
 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrew, have you run the example as is, or on the Event Dispatch thread? The code using EDT might be:
I'm trying to understand whether this is a Swing bug or not.
 
cate anderson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Martin
I tried your posted code. And it seems to clear up the problem. The code runs as it should.
I use the event dispatcher with my own research programs, but it is a bit overwhelming for novice programers so I don't introduce it until the advanced course. It has never been an issue before which is what floored me.

Andrew, just knowing someone else had seen the issue made me feel less alone!

Thank you both for your effort. I am glad I stopped spinning my wheels and asked for advice. Also very glad to know there are knowledgeable javites out there I can ask question to.

Picture me happy!!!

 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear the issue is cleared up!

Though I'm not a teacher, I can quite understand that teaching Swing to novice programmers is difficult. I'd suggest just to tell them that they need to put a few lines of code (the SwingUtilities.invokeLater stuff) into their projects as a necessary precondition which will be explained later.

I also think it is better this way. Unlearning bad habits is more difficult than learning the good practices right from the start, in my opinion (an opinion fostered by all that SQL-injection prone code seen in our JDBC forum). But then, perhaps this is why I'm not a teacher...
 
reply
    Bookmark Topic Watch Topic
  • New Topic