Java Tips Weblog

  • Blog Stats

    • 2,530,131 hits
  • Categories

  • Archives

Tile Icon

Posted by Darryl Burke on April 22, 2012

The usual way to repeat, or tile a background image across and down a GUI component is to write nested loops in a paintComponent(…) override.  TileIcon extends ImageIcon to provide this functionality and can fill the background of a component that can display an Icon.

Read the rest of this entry »

Advertisement

Posted in Extensions, Swing | 2 Comments »

Thumbnail Icon

Posted by Darryl Burke on April 14, 2012

In the last two posts, we presented StretchIcon and ShrinkIcon, both used for scaling images to fit a component whose size is determined by the size and layout of its container.  ThumbnailIcon extends ShrinkIcon to reduce an image when needed to fit within a defined size, padding and centering it horizontally or vertically as required.  Like ShrinkIcon, this class does not magnify the image.

Read the rest of this entry »

Posted in Extensions, Swing | Leave a Comment »

Shrink Icon

Posted by Darryl Burke on April 8, 2012

When writing about StretchIcon, published earlier, I mentioned that the image chosen for a StretchIcon should be large enough that it does not get magnified in fitting it to the component, since drawing an image larger than its natural size can lead to pixelation.  ShrinkIcon extends StretchIcon to ensure such pixelation doesn’t happen.

Read the rest of this entry »

Posted in Extensions, Swing | 2 Comments »

Stretch Icon

Posted by Darryl Burke on March 31, 2012

An implementation of the Icon interface reports its size via the two methods getIconWidth() and getIconHeight().  It’s normal to expect that the Icon’s paintIcon(Component, Graphics, int, int) method will respect these bounds.  If I had designed Swing’s interaction with Icons, I would have made sure of that by setting a clip to the Graphics passed to paintIcon(…).

Luckily for me, I didn’t design Swing, as that would have made StretchIcon impossible.

Read the rest of this entry »

Posted in Extensions, Swing | 27 Comments »

Drag Layout

Posted by Rob Camick on October 23, 2011

We have been taught that you should always use a layout manager to layout components on a container. But what about the times when you want the ability to randomly position components on a panel by dragging them with a mouse? Should we use a null layout or can we still use a layout manager?
Read the rest of this entry »

Posted in Classes, Swing | 5 Comments »

Table Column Manager

Posted by Rob Camick on May 8, 2011

When using a JTable the user has some control over the view of the columns in the table. The columns can be resized and they can be reordered. One feature that is not supported is the ability to hide and reshow a column.
Read the rest of this entry »

Posted in Classes, Swing | 24 Comments »

Marquee Panel

Posted by Rob Camick on April 24, 2011

A marquee is used to scroll a text message across the screen. The marquee components I’ve seen generally take a text string as a parameter for the marquee class. Then the plain text is scrolled across the screen. Wouldn’t it be nice to jazz up your marquee by using stylized text or by adding images to the marquee?
Read the rest of this entry »

Posted in Classes, Swing | 24 Comments »

Combo Box Popup

Posted by Rob Camick on November 28, 2010

The standard popup for a JComboBox is displayed below the combo box and is fixed to the actual width of the combo box. In most cases this the desired behaviour as the width of the combo box is determined by the items in the combo box. However there might be times when the combo box is not displayed at its preferred width. In these cases the rendering of the text in the popup may cause some items to be truncated. I’m sure this is not desireable.
Read the rest of this entry »

Posted in Classes, Swing | 22 Comments »

Escape Key and Dialog

Posted by Rob Camick on October 17, 2010

In some applications that use dialogs the Escape key can be used to close the dialog. This feature is not support in the base JDK but can easily be added.
Read the rest of this entry »

Posted in Classes, Swing | 2 Comments »

Keeping Menus Open

Posted by Darryl Burke on September 12, 2010

The default behavior of menus on all platforms, not just in Java, is for the menu to disappear when any item is selected. But once in a way, one comes across a situation where keeping the menu open could improve the user experience. For example, in the “Quick Preferences” submenu in Opera browser, a user who wants to set more than one option is forced to navigate the menu repeatedly.

Fortunately, the flexibility afforded in terms of extending the JDK classes makes this possible in Java.

Read the rest of this entry »

Posted in Classes, Extensions, Swing, Tips | 17 Comments »