File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Features new in Java 7 and the fly likes Trouble with Java 7 on a mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Trouble with Java 7 on a mac" Watch "Trouble with Java 7 on a mac" New topic
Forums: Swing / AWT / SWT Features new in Java 7 Mac OS
Author

Trouble with Java 7 on a mac

cate anderson
Greenhorn

Joined: Mar 01, 2014
Posts: 3
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!
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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

Joined: Mar 01, 2014
Posts: 3
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 Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

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).


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

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 Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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

Joined: Mar 01, 2014
Posts: 3
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 Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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...
 
Don't get me started about those stupid light bulbs.
 
subject: Trouble with Java 7 on a mac