Archive for the ‘Extensions’ Category
Posted by Darryl Burke on April 18, 2009
The default, and usually desired, behavior of a scrollbar is to continuously scroll its associated component while the scroll thumb is being dragged. There are at least two situations where this behavior may lead to a sluggish and unresponsive GUI:
- A complicated custom renderer bogs down the processor
- The contents to display are dynamically loaded from disk as the portions of the scrollable component are shown.
JumpScrollBarModel provides a behavior akin to clearing the option “Show window contents while dragging” on Windows. The scrollable component’s position will remain fixed while dragging the scroll thumb, and will update when the drag is terminated by releasing the mouse button. An optional setting allows for updating the scroll position when the mouse is paused for a user-defined interval.
Read the rest of this entry »
Posted in Extensions, Swing | Leave a Comment »
Posted by Darryl Burke on March 25, 2009
Discovering the hard way that the part of a JCheckBox or a JRadioButton that indicates its selected or rollover status is in fact the default icon of the component, and that invoking setIcon replaces the default icon with your custom icon, can be disconcerting or even exasperating.
CheckBoxIcon and RadioButtonIcon, which inherit from DualIcon, published earlier, through an abstract class ToggleButtonIcon, allow you to add a custom icon to these Swing components alongside the functional one.
Read the rest of this entry »
Posted in Extensions, Swing | Leave a Comment »
Posted by Darryl Burke on March 6, 2009
Does your JTable have short column content, but long column names? Do the column headers take up more horizontal space than you can spare?
No longer do you need to resort to cryptic two and three letter column headings in an attempt to solve this problem. Just rotate your table header text to the vertical, using VerticalTableHeaderCellRenderer.
Read the rest of this entry »
Posted in Extensions, Swing, Table | 9 Comments »
Posted by Darryl Burke on February 27, 2009
The javax.swing package and its subpackages provide a fairly comprehensive set of default renderer implementations, suitable for customization via inheritance. A notable omission is the lack of a default renderer for a JTableHeader in the public API. The renderer used by default is a Sun proprietary class, sun.swing.table.DefaultTableCellHeaderRenderer, which cannot be extended.
DefaultTableHeaderCellRenderer seeks to fill this void, by providing a rendering designed to be identical with that of the proprietary class, with one difference: the vertical alignment of the header text has been set to BOTTOM, to provide a better match between DefaultTableHeaderCellRenderer and other custom renderers.
Read the rest of this entry »
Posted in Extensions, Swing, Table | 6 Comments »
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 »
Posted in Extensions, Swing | 2 Comments »
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 »
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 | Leave a Comment »
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 »
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 »
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 »