Java Tips Weblog

Archive for the ‘Classes’ Category

Text Field Auto Tab

Posted by Rob Camick on October 25, 2009

Anybody who has ever written a DocumentFilter has probably seen the DocumentSizeFilter example from the Swing tutorial on “Implementing a DocumentFilter”. It is simple, straight forward and works well. However, wouldn’t it be nice to have some additional functionality, namely the ability for auto tabbing when the Document is full?
Read the rest of this entry »

Posted in Classes, Swing | 3 Comments »

Chaining Document Filters

Posted by Rob Camick on October 18, 2009

A previous entry on Text Validation briefly mentions why you should consider using DocumentFilters. A limitation of a DocumentFilter is that you can only add a single filter to the Document. There may be times when you need to filter on multiple conditions. Of course you can always create a new filter and combine the code for multiple filter conditions. However, an easier approach would be to reuse existing filters. That is, it would be nice to be able to chain multiple filters together to act as a single filter.
Read the rest of this entry »

Posted in Classes, Swing, Uncategorized | Leave a Comment »

Component Border

Posted by Rob Camick on September 27, 2009

There are many times when you want a JTextField and a JButton to work together. That is you provide the user with a text field for entering data and you provide a button to display a popup component to make it easier to enter the data. An example might be a date field. Some users might choose to type the date directly into the text field, while others might choose the point and click approach. There are a couple of common appoaches for achieving this and one not so common approach that I will suggest.
Read the rest of this entry »

Posted in Classes, Swing | 5 Comments »

Resizing Components

Posted by Rob Camick on September 13, 2009

A recent entry on Moving Windows discussed how you might add functionality to move a component or a non decorated window. Today we will look at adding resizing functionality to these same components.
Read the rest of this entry »

Posted in Awt, Classes, Swing | Leave a Comment »

Disabled Panel

Posted by Rob Camick on August 2, 2009

A previous entry discussed a DisabledGlassPane which allows you to disable key and mouse events for an entire frame. There may be times when you need to disable key and mouse events for a given Container only. Unfortunately you can’t just invoke setEnabled(false) on the container to disable the contained components. So we need another approach.
Read the rest of this entry »

Posted in Classes, Swing | 2 Comments »

Overlap Layout

Posted by Rob Camick on July 26, 2009

All the layout managers, that I’m aware of, position components in a separate area of a container. This makes sense as you generally don’t want components to overlap one another. However, there may situations, in a card game for example, where it is reasonable to have components overlapping one another. I haven’t played with the ZOrder support that was added in JDK5, but I figured this might be a way to support overlapping components.
Read the rest of this entry »

Posted in Awt, Classes | Leave a Comment »

Table Button Column

Posted by Rob Camick on July 12, 2009

A JTable is used to disply rows of data. There may be times when you want to do some processing on a row of data. Maybe you want to display a popup form with more details or maybe you simply want to delete a row. In these cases it may be desireable to add a button to one of the table columns so you can invoke this processing. The problem is that JTable doesn’t support a button renderer or editor.
Read the rest of this entry »

Posted in Classes, Swing | 7 Comments »

HSL Color

Posted by Rob Camick on July 5, 2009

The Color class in Java uses Red, Green and Blue (RGB) values to specify a Color. I don’t know about you, but I have no idea how to manipulate a given Color to return a related Color. For example, how would you go about returning a darker or lighter Color? Sure the Color API supports brighter() and darker() methods, but they don’t seem to work that well and you can’t control the degree of brightness or darkness. The API also supports a HSB (Hue, Saturation, Brightness) color space which seemed promising, but didn’t quite return the results I was looking for.
Read the rest of this entry »

Posted in Awt, Classes | 4 Comments »

Combo Box Table Editor

Posted by Rob Camick on June 28, 2009

When using a JComboBox as an editor in a column of a JTable the same combo box is used for all rows in the column. There may be times when you want different rows to use a different combo box.
Read the rest of this entry »

Posted in Classes, Swing | Leave a Comment »

Animated Icon

Posted by Rob Camick on June 21, 2009

I’m sure everybody has seen or used animated gifs on a webpage. As far as I know an animated gif is created using an image editor and the images and animation information is contained within a single gif file. Have you ever thought about dynamically creating an animated gif? Well, I don’t know how to do that, but I might have an approach that will work just as well.
Read the rest of this entry »

Posted in Classes, Swing | Leave a Comment »