Tuesday, December 7, 2010

JComboBox Text Alignment

Today someone asked me how can we make the text in a JComboBox align to the right instead of the left? Here's your answer :)

DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
 //DefaultListCellRenderer.LEFT;
 //DefaultListCellRenderer.CENTER;
 //DefaultListCellRenderer.RIGHT;
 dlcr.setHorizontalAlignment(DefaultListCellRenderer.RIGHT);
 jComboBox1.setRenderer(dlcr);

Import this,
import javax.swing.DefaultListCellRenderer;
and your done.


Monday, December 6, 2010

How to set an Application Icon in Swing

To set an application icon simply paste this code in you application:

InputStream icon = this.getClass().getResourceAsStream("MyIcon.gif");
if (icon != null) {
   BufferedImage image = ImageIO.read(icon);
   setIconImage(image);
}

Swing components, such as labels and buttons can be decorated with an icon by using the Icon interface: IconImage.

Thursday, December 2, 2010

Oracle and Apple Announce OpenJDK Project for Mac OS X

This may be old news, but apparently Oracle and Apple announced the OpenJDK project for Mac OS X.
“We are excited to welcome Apple as a significant contributor in the growing OpenJDK community,” said Hasan Rizvi, Oracle’s senior vice president of Development. Personally I'm more eager to see how Oracle, Apple and the JAVA community will handle the issue of Apple's use of private API in their JAVA development.

Let's just hope that Apple's implementation doesn't end up like Microsoft's :(

For more information on JAVA and on the subject, visit: