Skip to main content

Java

Glue category for everything related to Java.

Java, Linux and using the desktop's stock icons in a Swing GUI

Posted in

Well, Java is cross platform, granted. But if you want your application to look native to the user's desktop environment, you have to jump through a lot of hoops (and some of them are burning, too). Take icons, for example. Nowadays, an application is expected to use icons in menuentries and on the toolbar to increase usability. Nothing wrong with that, except that Swing does not ship with any. You have to provide your own and you have to bundle them with your application. For Windows and MacOS, that's ok.

WhereAmI: Locating the installation directory of your Java application

Posted in

Know what I really hate about Java? This half-assed attempt at establishing a virtual filesystem. On one hand, you have the java.io package by which you can access the native filesystem of the host OS, on the other, you are suppose to load every application resource via ClassLoader.findResource(). Got a resource, you can't reasonably bundle in a JAR file (e.g. because you have to update/modify it occasionally)? Tough luck!

Executing a child process and redirecting output to a JTextArea

Posted in

Seems like Java developers shun the idea of having to do anything out of their cozy virtual machine, so I couldn't find any good code examples for doing this problem: Fork a new JVM from your current JVM and capture it's stdout/stderr stream to a JTextArea. Allow the user to kill the subprocess at any time.

Well, here's my solution:

import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
import java.io.*;
 
public class ForkDemo implements ActionListener {
 
  protected JTextArea output = new JTextArea(10,20);

...Java applications just never work straightaway

Posted in

I keep repeating the same stupid mistake over and over again: A friend needs a tool to accomplish $FOO, so I quickly hack together a simple BAR application that should do the trick. I test it and after deciding that it can't possibly break, my friend manages to break it in an instant. Now, the fun starts. I pretty much know that an exception must have been thrown somewhere. The only problem is accessing it. These days, users are just so incapable of running a program from the commandline, in order to copy and paste whatever got written to the console.

Release Notes: Table2GridBag (1.6)

Posted in
Spec Sheet
Name: 
Table2GridBag
Version: 
1.6

Changelog:

  • Added support for the CAPTION tag. You can now specify the fully qualified classname for the generated code by either submitting it via the -Dclass= commandline argument or by giving the table a caption with the name (commandline always overrides the caption).

Release Notes: Table2GridBag (1.5)

Posted in
Spec Sheet
Name: 
Table2GridBag
Version: 
1.5
  • Bugfix: Fixed import statements in generated code to include java.awt.Container (was causing trouble when auto generating components to fill empty table cells).
  • New feature: Generated code now includes a create(Object) builder method. This method takes an object and uses reflections to extract the components (by name), the layout specifies. This, of course, requires that this object declares the components by these names as public or protected fields.

Release Notes: Table2GridBag (1.4)

Posted in
Spec Sheet
Name: 
Table2GridBag
Version: 
1.4
  • Added -Dextends property to specify a class (FQN), generated classes will extend (default is "java.awt.Container")

A method for handling I18N in Java

Posted in

Let's talk about Java and internationalization. Java makes a pretty clear point about being platform independent and so it's only logical to also try to keep user interfaces language neutral. When you read the Java I18N trail however, it more or less only tells you to use ResourceBundleS, but keeps rather quiet about best practice. What you are essentially left alone with are the four most important questions:

  • What's a good naming scheme for keys?
  • How do you organize the property files?

Swing MDI: coming up with a window placement algorithm for JInternalFrameS / JDesktopPaneS

Posted in

This is utmost annoying: Swing MDI has been around for ages and nowhere there's a decent, ready to use window placement algorithm to be found. I mean, I understand that there's no one size fits all solution to this problem, but you should at least expect some example code somewhere. The JDesktopPane class is pretty much useless if you are just going to pop up your JInternalFrameS at 0,0 and then expect the user to arrange them. Yet, nothing, zip, zilch that would even give you an idea of writing a window positionier.

Java, applications and user feedback: which program version are you using anyway?

Posted in

Do you know this kind of situation? You get an email - A bug report for one of your applications and it kinda reads like: "Help, your app is broken - please fix it". Now it's your job to help the user figure out which application is meant (assuming your portfolio contains several) and more importantly, which version of that application s/he is actually using. A task, that usually includes sending back and forth a number of extra emails, just to explain how to gather the required information.

Syndicate content