Java Tips Weblog

  • Blog Stats

    • 2,065,823 hits
  • Categories

  • Archives

  • Advertisements

Archive for the ‘Classes’ Category

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 | 21 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 | 17 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 »

Multisort Table Header Cell Renderer

Posted by Darryl Burke on August 29, 2010

It’s easy to make a JTable sortable by invoking setAutoCreateRowSorter(true). Clicking on the header of a column will then sort the rows on the basis of the contents of the cell in that column, and display an appropriate arrow icon. A little known fact is that the default, automatically created, RowSorter actually uses the last three sort indexes. Unfortunately, the only way the user can know which columns are involved in the subordinate sorting is by remembering the sequence in which the columns were clicked.

MultisortTableHeaderCellRenderer addresses this deficiency by showing the sort icons with decreasing opacity on all columns involved in the sort, making use of the AlphaIcon class published earlier.

Read the rest of this entry »

Posted in Classes, Extensions, Swing, Table | 4 Comments »

Alpha Icons

Posted by Darryl Burke on August 22, 2010

These Alpha Icons wrap any Icon and paint it with the specified transparency. As Swing does not play well with an Icon that is not itself an ImageIcon but requires to show an animated GIF, two implementations are provided: AlphaIcon, which is good for wrapping any Icon, including an ImageIcon with a static image, and AlphaImageIcon which extends ImageIcon and can provide transparency for an ImageIcon that holds an animated image.

Read the rest of this entry »

Posted in Classes, Swing | 5 Comments »

Scrolling a Form

Posted by Rob Camick on May 9, 2010

It is easy to create a form, you just create a panel and add some components to it. It is also easy to make the form scrollable, you just add the panel to a scroll pane. However, maybe you’ve noticed that as you tab from component to component the viewport of the scroll pane does not scroll automatically when the focused component is no longer in the viewport? In many cases the form would be more usefull to the user if it would scroll automatically as focus changes from component to component.
Read the rest of this entry »

Posted in Classes, Swing | 6 Comments »

Formatted Text Field Tips

Posted by Rob Camick on February 21, 2010

A JFormattedTextField provides the ability for text to be formatted depending on the formatter specified. This formatting causes the formatted text field to behave differently than other text components in some cases. It also makes it a little more difficult to customize the behaviour in other situations.
Read the rest of this entry »

Posted in Classes, Swing, Tips | 5 Comments »

Mouse Wheel Controller

Posted by Rob Camick on January 10, 2010

The mouse wheel can be used to scroll the viewport in a scroll pane. Have you ever wondered how the scroll amount is determined? Better yet, have you ever wanted to control the scroll amount?
Read the rest of this entry »

Posted in Classes, Swing | 4 Comments »

Scrollable Panel

Posted by Rob Camick on December 20, 2009

When using a JScrollPane the general rule is that the scrollbars will appear when the “preferred size” of the component added to the JViewport of the scroll pane is greater than the “size” of the viewport. There may be times when you wish to prevent a scrollbar from appearing even though the preferred size is greater than the size.
Read the rest of this entry »

Posted in Classes, Swing | 25 Comments »