JPanel Mouse Events
Forum Post (more soon) Tha Java Song
By Ben 28 Aug 2008
Pluggable Look and Feel
I have found a look and feel that I think is quite nice, it fits well with the default swing L&F style and looks quite nice Kunstoff Look and Feel.
JTable Customisation
Recently I have started a project (JavaTunes) a copy of an existing programme that I intend to release in an open-source form. All the components of this application are open source already so I see no reason why I shouldn't be able to poke around. Anyway, one thing I want to do is alter the behaver of the JTable. To allow single click editing of each cell have a look here: Single Click Edit a JTable Cell.
I will put some more here as I learn ;-).
JTable Row Selection without the selected cell border
Easy, just override the prepareRenderer() method in the JTable class.
songsListTable = new JTable(songsListModel) {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
boolean focused = isFocused();
boolean selected = isCellSelected(row, column);
if (c instanceof JComponent) {
JComponent jc = (JComponent)c;
if (isEditing() == false) {
Border border;
border = BorderFactory.createEmptyBorder(1, 1, 1, 1);
jc.setBorder(border);
}
}
return c;
}
};
Swing Anti-aliasing
How hard can it possibly be to get Swing (Java's GUI Toolkit) to work with Anti-aliased text? Well not difficult but you can have a hard time finding how to on the internet because of confusion with the 1.5 property swing.aatext. This does not work in Java 1.6 (codename Mustang) for this version of the JDK and JRE to anti-alias text one must use the awt.useSystemAAFontSettings.
And so, to summarise to get Anti-aliased fonts in Swing add this line to your swing.properties file: Wrong!
awt.useSystemAAFontSettings=on
Or set your environment variable _JAVA_OPTIONS to include:
-Dawt.useSystemAAFontSettings=on
or put this line in your Java programme code:
System.setProperty("awt.useSystemAAFontSettings", "on");
You can find out more about this and System properties at Sun's Java2D System Properties guides. Or for more about look and feel, including how to revert to the original Purple and Grey Metal theme, see How to Set the Look and Feel.
By Ben 15 May 2008
