Java Tips Weblog

  • Blog Stats

    • 1,494,825 hits
  • Categories

  • Archives

Archive for the ‘Swing’ Category

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 | 4 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 »

Dialog Focus

Posted by Rob Camick on March 14, 2010

When a JDialog (or JFrame for that matter) is made visible, focus is placed on the first focusable component by default. There may be times when you want to change this behaviour. The obvious solution would be to invoke the requestFocusInWindow() method on the component you wish to receive focus. The problem is that this doesn’t work all the time.
Read the rest of this entry »

Posted in Application, Swing, Tips | 36 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 »

Table Row Rendering

Posted by Rob Camick on January 24, 2010

There are times when you might want to do some custom rendering for an entire row of a table. Based on answers I see in the forums, for most people the first thought is to create a custom renderer. This can be a simple solution in some cases, but are there other alternatives to consider as well?
Read the rest of this entry »

Posted in Swing, Tips | 20 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 »

Text Prompt

Posted by Rob Camick on November 29, 2009

Generally text fields are paired with a label when added to a GUI. The label describes the contents of the text field. In some applications you may have noticed that a text prompt appears inside an empty text field. This might be done when space is at a premium or you need to provide addition formatting information for the text.
Read the rest of this entry »

Posted in Classes, Swing | 22 Comments »

ToolTips and ScrollPanes

Posted by Rob Camick on November 8, 2009

Tooltips are generated by mouse movement over different Swing components. In a complex component, like a JTable, the tooltip is continually updated as the mouse moves from cell to cell. But what happens when the table is in a scrollpane and the viewport is moved? In this case the mouse may now be hovering over a different cell, but the tooltip is not updated. This may, or may not, be a problem depending on your requirements.
Read the rest of this entry »

Posted in Classes, Swing | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 103 other followers