Monday, October 20. 2008
A Java Swing user interface I am working on which makes extensive use of a custom JTableModel implementation was failing. In certain instances when my data structure changes, it purges empty cells. If the cursor was left in these cells while this was taking place, the table would become unresponsive, often requiring an application restart to fix.
Watch for issues with setValueAt, which in some cases can be called with invalid values. In particular if the cursor is editing a field, the table is not refreshed until the edit focus leaves the widget even if you try to force it with validate() calls. In my instance the ideal fix was to add checks and do nothing instead of throwing exceptions.
With getValueAt, some table widget types choked on my default of null, which I was returning for invalid cells. Using an empty string instead of null for these invalid cells fixed this problem.
Wednesday, September 17. 2008
Firefox 3 introduces a new behavior when your doctype is XHTML Strict; certain tags that do not allow minimization as per the spec no longer close anyway. For example, if you use a <script src="blah.js" /> tag in your heading, Firefox 3 will take the whole rest of the page as a script, which will result in a blank page. This is good as it enforces standards compliance, however jspx minimizes tags, so you may have <script src="blah.js"></script> on your page, but the actual rendered page will minimize it.
There are many ways to fix this issue by playing tricks on jspx, I recommend:
<script src="blah.js"><!-- //prevent jspx minimization --></script>
This reminds me when I'm working on the code why that comment is there. Hopefully this will be fixed in the jspx spec at some point.
Thursday, June 5. 2008
A project I am working on requires binary image files and form data to be submitted simultaneously. This is rather easy to do with Spring, following the directions available in the latest documentation to handle file uploads in a form. It does not mention there that you can mix form fields as well as file upload fields when doing this, but it works as expected.
Continue reading "Spring Binary and Text Forms"
Wednesday, February 27. 2008
Here is the easiest process I have found for setting up Ruby and PostgreSQL on OS X Leopard at this time.
I recommend PostgreSQL for Mac instead of fink as it is more actively maintained and easier to install. Note that when downloading, use the alternate download not the Sourceforge links, as the Sourceforge download is not current and has issues. This installer places the PostgreSQL CLI commands in /Library/PostgreSQL8/bin/ and will auto-start PostgreSQL on system startup. It includes some graphical tools, but I recommend ignoring them and and installing pgAdmin III if you want an administration GUI (I usually just use the CLI tools).
Ruby has a couple PostgreSQL gems, I recommend ruby-pg which appears to be the only one actively maintained. The easiest way to get it installed is to download the latest .gem, then run the following command to install it in the directory where you saved it (replace the version number as necessary):
PATH=$PATH:/Library/PostgreSQL/bin/ gem install pg-0.7.9.2008.02.05.gem
Don't waste your time trying to find documentation for this gem online, point your browser at the documentation on your local machine, which for this version was at:
file:///Library/Ruby/Gems/1.8/doc/pg-0.7.9.2008.02.05/rdoc/index.html
Thursday, December 20. 2007
When storing preferences for applications on Java, there is a built in Preferences API. If you need full control of preference storage or need to change it from applications external to Java or manually, one of the options I discussed last year may be better (if you need an XML file in a specific location for example), but if you just need simple cross-platform preference storage, the built in option is ideal.
Usage Summary
import java.util.prefs.Preferences;
Preferences prefs = Preferences.userNodeForPackage( getClass() );
prefs.get("keyName", "default value");
prefs.put("keyName", "new value");
The JavaDoc for it is quite confusing, so try this tutorial on java.util.prefs.Preferences instead.
Thursday, December 6. 2007
Netbeans 6 has been released. I have been using it since beta 1 and have found it an invaluable improvement over the old version. The editor and layout is improved, and subversion support is now built in. The major change in this release is the language support; Ruby support is now available, and there is a PHP plugin. I'll report as I try these other plugins over the next few weeks.
Tuesday, October 30. 2007
When building Swing applications customized for OS X, note that for more complex applications with multiple JFrames, a JFrame containing a JMenuBar must be initialized first. If a JFrame with no JMenuBar is created first, neither the custom application name nor the menus will work correctly.
Continue reading "OS X: JFrame with JMenuBar Must Be First"
Thursday, October 25. 2007
Wish you could have multiple keys in your Map class? Want to add constraints easily to your collections to ensure the data is as expected? Both of these and much more are available in the Google Collections Library. Obviously these can be coded yourself; but this library offers a more elegant and better tested way to build some of these useful data structures.
Wednesday, October 10. 2007
When receiving the error java.net.MalformedURLException: unknown protocol: dummy, check everything included in all libraries and classpath elements for old or conflicting versions of Xerces and Gnu Jaxp. Dummy is a basic, built-in protocol, so if it is not locatable there is a library conflict.
Thursday, September 20. 2007
Getting blank pages from your java.awt.print.Printable implementation? Check for null pointer exceptions. Uncaught null pointer exceptions generated by your implementation of print() method are silently thrown away. I have noticed this behavior on Java build 1.5.0_07-164 on OS X.
Thursday, August 9. 2007
I was getting an error when trying to run ant junit on a project from the command line for a Netbeans 5.5 project. There are many hard to humanly parse solutions out there via Google. The solution that worked for me:
Continue reading "Netbeans 5.5 'ant junit' Not Working from Command Line"
Thursday, May 31. 2007
When using the subversion client built into Netbeans 5.5 on OS X with the svn+ssh protocol, it ignores the username entered and always uses the logged in user's username. This occurs both when entering a username in the field for it and when using a url like svn+ssh://username@server.com/svnrepo. Fortunately if you encounter this problem, there is a workaround:
svn+ssh://username@username@server.com/svnrepo
Netbeans only strips the first username@, leaving the second one in place. Everything then works as the correct URL gets properly embedded in the right places.
Continue reading "Netbeans svn+ssh Username Glitch"
Monday, May 21. 2007
Looking for an easy way to launch a browser window from your swing application? The easiest solutions I found without using a library involved JNLP; not a good answer for my cross platform Swing applications. There are quite a few solutions, but I like Browser Launcher 2. Only 92kb, it seems rather good at finding the user selected system default browser, and its ease of use is hard to deny:
BrowserLauncher().openURLinBrowser("http://example.com");
Wednesday, May 9. 2007
I have been using the PDFBox library when working with PDF files, most commonly to extract the text for lucene indexing and generating thumbnails conveniently in Java. Recently I have started to see this error when generating thumbnails, which come out as properly sized plain white pages:
java.io.IOException: Unknown stream filter:COSName{JBIG2Decode}
Some of the latest PDFs, in this case from a new Xerox copier (which scans into PDF format), generates black and white images in PDFs using the JBIG2 format. Java has no built-in support for JBIG2 yet, and building a handler for this image type into the PDFBox library isn't an option for the development team at this time.
Continue reading "Java Lacks JBIG2 Image Support"
Thursday, March 15. 2007
After the Harrisburg Java User's Group meeting tonight, two items in particular came up in the post-presentation discussions which I am mentioning here mainly for my own reference, but will likely be valuable to anyone reading this doing Java programming.
The Java 2 Platform, Standard Edition 5.0 Trouble-Shooting and Diagnostic Guide is a comprehensive guide to the tools that are available as part of JDK5 to analyze Java programs. Interestingly many of these tools do not exist on Windows, but they are in OS X as well as the mentioned Linux and Solaris.
Available as part of the stock Java 5 standard libraries, the JSR 166 Concurrency Utilities allow the building of many common concurrency models without the complication of doing such programming from scratch. Concurrent programming is becoming important as more cores become increasingly dominant in modern computers.
|