Java Tips Weblog

  • Blog Stats

    • 2,167,869 hits
  • Categories

  • Archives

  • Advertisements

Archive for the ‘Extensions’ Category

Vertical Label UI

Posted by Darryl Burke on February 21, 2009

Once in a way, one comes across a situation where the ability to render text vertically – rotated 90° – could both conserve screen real estate as well as make for a more aesthetic GUI.

VerticalLabelUI, which extends BasicLabelUI, provides a comprehensive solution to such need.

Read the rest of this entry »

Advertisements

Posted in Extensions, Swing | 13 Comments »

Combo Box With Separators

Posted by Rob Camick on February 15, 2009

A combo box displays a drop down list of items. Usually all the items in the list are related to one another. Occassionally, you may have a need to show a list of unrelated items. In this case it would be nice to separate the items in the list visually. However, unlike a popup menu, a combo box popup does not support the use of separators.
Read the rest of this entry »

Posted in Extensions, Swing | 3 Comments »

Single Root File Chooser

Posted by Rob Camick on January 28, 2009

The JFileChooser component allows a user to select a file from anywhere in the File System. The “Look In” combo box allows you to move around the File System easily to find the file you are looking for. However, there may be times when you want to restrict the user to searching a specific directory tree. Therefore, we need to control the entries displayed in the “Look In” combo box.
Read the rest of this entry »

Posted in Extensions, Swing | 13 Comments »

Center Line in Scroll Pane

Posted by Rob Camick on January 4, 2009

Generally, a multi-line text component is added to a scroll pane so that all the lines contained in the text component can be viewed by scrolling through the scroll pane. The caret indicates the current line. When the setCaretPosition() method of the text component is invoked the scroll pane will scroll to make sure the current line is always visible. Therefore, one of three possible scrolling outcomes will occur:

  • no scrolling happens when the current line is within the current viewport of the scroll pane
  • scroll such that the current line is displayed at the top of the scroll pane
  • scroll such that the current line is displayed at the bottom of the scroll pane

There may be times when you wish the current line to be positioned in the center of the scroll pane.
Read the rest of this entry »

Posted in Extensions, Swing | Leave a Comment »

Icon Table Cell Renderer

Posted by Darryl Burke on December 18, 2008

The suplied default renderer for JTable columns of class Icon and ImageIcon, JTable.IconRenderer, is known to give rise to a ClassCastException when attempting to render an Icon whose implementation of paintIcon(…) requires a cast of its Component parameter to a specific subclass of Component. Several icons obtained from standard JDK classes trigger this ClassCastException.

IconTableCellRenderer addresses this issue by attempting to paint the Icon in 3 different ways before falling back on a default icon which can be customized via a parameter to the constructor.

Read the rest of this entry »

Posted in Extensions, Swing, Table | 7 Comments »

File Class Loader

Posted by Darryl Burke on December 9, 2008

Loading a Java class identified at runtime can be a daunting task. When faced with the challenge, one naturally turns first to the standard ClassLoader and its subclasses. However, many methods that look interesting are protected and/or final, and cannot be used directly.

FileClassLoader extends java.net.URLClassLoader to provide useful functionality for loading a class from its compiled class file.

Read the rest of this entry »

Posted in Extensions, Net | 2 Comments »

Component Tree Cell Renderer

Posted by Darryl Burke on November 16, 2008

A previous posting, Component Tree Model, showed how to reproduce the hierarchy of a GUI in a JTree. The default node rendering in a JTree is the String returned from invoking toString(). For reviewing the nesting of components in a GUI, a visual rendering is infinitely more useful and appealing.

ComponentTreeCellRenderer provides this functionality and, when used in conjunction with a ComponentTreeModel, provides all you need to analyze the layout of a GUI in minute detail.

Read the rest of this entry »

Posted in Extensions, Swing | 4 Comments »

Component Tree Model

Posted by Darryl Burke on November 15, 2008

The code for a complex GUI can run into a few hundred lines. When maintaining someone else’s GUI code, or even your own code that you haven’t visited for some time, the ability to quickly identify the nesting of the various components can save much code-searching.

ComponentTreeModel attempts to address this need by reproducing the hierarchy of a GUI as a TreeModel.

Read the rest of this entry »

Posted in Extensions, Swing | Leave a Comment »

Sorted Combo Box Model

Posted by Rob Camick on November 11, 2008

A JComboBox displays the items in the drop down list in the order in which the items where added to the combo box. If you want the items sorted then you can use the Collections.sort() or Arrays.sort() methods on the data before you create the combo box model. But what if you have a dynamic combo box and you want to keep the items in sorted order as new items are added?
Read the rest of this entry »

Posted in Extensions, Swing | 11 Comments »

Select Button Group

Posted by Darryl Burke on November 9, 2008

Anyone using ButonGroup for the first time has scoured the API for a method that returns the selected Button.   Alas, getSelection() returns a ButtonModel, not a button.   And as the MVC pattern of Swing allows a visual component – a View – to share its Model with other visual components, ButtonModel rather obviously doesn’t provide a method to get the button from its model.

SelectButtonGroup attempts to address the shortcomings of ButtonGroup by providing additional methods that shorten user code and make programs using the class easy to write and maintain.   The class also offers property change support on the same lines as visual components.

Read the rest of this entry »

Posted in Extensions, Swing | 4 Comments »