Showing posts with label Swing Components. Show all posts
Showing posts with label Swing Components. Show all posts

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.

Friday, November 26, 2010

Working with JTables

With JTables you can display tables of data, allowing the user to edit the data. Fallow this example if you want to learn how to fill a specific position in a JTable.
  • Create a new JDialog Form.
  • Drag and drop the JTable swing component into the JDialog Form. You should have something like this,

Tuesday, November 16, 2010

Image inside a Scroll Pane

Today I'm going to show you how you can place an image inside Scroll Pane.

  • Create new JDialog Form,