If you want to add a nice touch to your GUI application, center your window on the screen. Not only does this looks much better than having it start up in the default (0, 0) location, but it takes very little coding effort to make this happen. Fortunately for us, there are two methods for doing this, depending on which version of Java you are using. I will show you how to do it both ways.
Archive for June, 2009
HOW-TO: Detect link clicks in JEditorPane
If you are using a JEditorPane to display HTML, and that HTML contains links, there is no built-in function to automatically detect if the user clicks on a link. What’s the solution to this problem? Create a HyperlinkListener. Here’s how…
HOW-TO: Java Gradient Backgrounds
Nowadays, if you are developing a GUI application, it looks more “professional” if your window’s background is gradient (i.e. the background fades from light to dark, or dark to light). This gives your application a more polished look and can greatly improve the interface without much effort. Here’s how to do it…
HOW-TO: Retrieve a File’s extension in Java
For some strange reason, there’s no getFileExtension() or getExtension() method in Java’s File class. Of course, that doesn’t mean we can’t do it on our own. All it takes is one line of code!
