Table of Elements JavaBean

See also our achievements for other projects
There are a lot of "Table of Elements" - applets on the internet. However, this one is written as a Java Bean, and it comes with source code ! The Java Bean itself is implemented as a JPanel, so that you can easily integrate it in other panels and containers, as part of a larger application. The bean has a large number of "getters and setters" so that you can easily adapt it to what you want with very little programming effort.
For example, you can:

Furthermore, when using the bean, you will see that a JColorChooser is connected to change the background color. Just click in the panel, but not on an element, and you will be able to choose the background color.

To demonstrate how this Java Bean can be used, I also wrote a custom dialog (TableOfElementsDialog.java), which incorporates the "Table of Elements" Java Bean. If you look at the source code of the dialog, you will see that there are two ways the dialog can be implemented. I made it a customized dialog, as I also wanted to choose my own colors and fonts for the "OK" and "Cancel" button. The classic way (using a JOptionPane) is commented away in the code. If you want to use the classic way, uncomment this part of the code, and comment the custom part.

A customized Table of Elements incorporated in a Dialog
When clicking the "OK" button, the Java Bean and dialog return arrays with the selected element numbers, element symbols, and element names (methods getSelectedElementNumbers(), getSelectedElementSymbols() and getSelectedElementNames() ). This will be usually the way you extract the necessary information from the Java Bean.

Here comes the demo as an applet. It actually does little, only pops up a textarea with the selected elements. As the "Table of Elements" comes as a Java Bean, you will of course be able to build your own much more interesting applications, with the Table of Elements as just one of the components.

</COMMENT>

This applet requires you to have the Java-2 plugin installed (it uses Swing components). If you do not have the Java-2 plugin installed, the browser will simply ask you to download and install it from the Sun Microsystems Java website. If you do not have the Java-2 plugin installed, and your browser does not install it automatically, go to the Sun website, go to the "Download Production Release 1.3" section and install the Java-2 plugin following the instructions.
The Java-2 plugin is just a plugin like the Flash-plugin and other plugins you already have. It is perfectly safe and especially useful for intranets.

Download

All source code is freely available. Feel free to use it, improve it, adapt it. All we ask is that you give credit to Computer Chemistry Consultancy in one way or another.
The code that was used for the applet and the dialog: The source code of the Java Bean: If you only want to use the Java Bean without bothering how it was implemented, you can just download the jar file and the API documentation:

Still to do:

At the moment multiple selection of elements is always allowed. The implementation of setAllowMultipleSelection(false) has not been performed yet. Hope to do this one of these days.

Other goodies

Jos Aerts, Computer Chemistry Consultancy, September 2001