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:
Change the normal color, mouse-over color, color when selected, of each element panel.
Change the color, font and size of the element numbers, element symbols and element names
Change whether you want to see the element names or not. Showing the element names can result in a too large
table, or element names that are barely readable (there are 103 elements included !). Mostly I set the
"setDisplayElementName" to "false".
Change whether you want to see the element names as tooltip text or not.
and many more things (see the API documentation).
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
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
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.
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.
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: