Java Tips Weblog

  • Blog Stats

    • 2,613,981 hits
  • Categories

  • Archives

Jump Scrollbar Model

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 »

Scrollbar Tooltip

Posted by Rob Camick on April 11, 2009

All Swing components support the usage of tooltips. If a tooltip is set for a given component then the tooltip will display when the mouse hovers over the component for a given period of time. Once the tooltip is displayed it may also be changed dynamically as the mouse moves over different areas of the component. Unfortunately this basic processing does not work for a JScrollBar. Typically a scrollbar will be dragged by the mouse, however the dragging action causes any tooltip that might be visible to be hidden (actually the mouse pressed causes the tooltip to be hidden). Therefore, a dynamic tooltip is not possible on a scrollbar.
Read the rest of this entry »

Posted in Classes, Swing | Leave a Comment »

Rotated Icon

Posted by Rob Camick on April 6, 2009

Icons are painted on a component in the orientation in which they where created. That is, the text in the TextIcon is painted in a left-to-right order. Image icons are painted as the image was created in the image editor. If we could change the orientation of the icon, then maybe we could create some interesting effects.

Read the rest of this entry »

Posted in Classes, Swing | 10 Comments »

Text Icon

Posted by Rob Camick on April 2, 2009

Whenever people think of a Icon, they usually think of an image of some kind. The image is a simple picture that is used to represent something (whatever that may be). The general purpose Icon class provided by the JDK is the ImageIcon class. Maybe it is time for another type of Icon? How about a TextIcon?
Read the rest of this entry »

Posted in Classes, Swing | 2 Comments »

Compound Icon

Posted by Rob Camick on March 29, 2009

Many Swing components support the usage of Icons. Icons can spice up your application when used effectively. You may be familiar with the old saying, “two heads are better than one“? Well, there may be times when two Icons are better than one.
Read the rest of this entry »

Posted in Classes, Swing | 4 Comments »

Toggle Button Icons

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 »

Dual Icon

Posted by Darryl Burke on March 22, 2009

Many Swing components accommodate an icon. What if you would like to display more than one icon on the same component, or show a custom icon on a component like JCheckBox or JRadioButton, in addition to the icon that the Look and Feel displays by default?

DualIcon to the rescue! This simple class facilitates making one icon from two. The composite icon can be applied to the component using setIcon.

Read the rest of this entry »

Posted in Classes, Swing | Leave a Comment »

Split Pane Synchronizer

Posted by Rob Camick on March 19, 2009

A JSplitPane is commonly used to display 2 related Components. A divider is painted between the two Components and the user can drag this divider to control the relative space available to each Component. An interesting usage of the split pane might be to nest split panes inside the main split pane.
Read the rest of this entry »

Posted in Classes, Swing | 4 Comments »

Table From Database

Posted by Rob Camick on March 12, 2009

A JTable is frequently used to display data retrieved from a database. The JDK does not support this directly but there are a couple of standard ways to implement this functionality:

  • use the ResultSet to implement the TableModel interface
  • copy the data from the ResultSet to an existing TableModel

For the first approach, just search the web using “ResultSetTableModel” and you will find many different implementations. The trick will be to find an implementation with all the features you require, or one you can customize to meet your requirements.

For the second approach, you can use the DefaultTableModel, or you may find it easier to use the ListTableModel introduced in a previous blog entry..

Read the rest of this entry »

Posted in Classes, Swing | 37 Comments »

Vertical Table Header Cell Renderer

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

 
Design a site like this with WordPress.com
Get started