Java Tips Weblog

  • Blog Stats

    • 1,912,677 hits
  • Categories

  • Archives

Archive for the ‘Awt’ Category

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

Global Event Dispatching

Posted by Rob Camick on September 6, 2009

As a user interacts with a GUI, by using the mouse or keyboard, Swing handles the interaction by dispatching events to the appropriate component for processing. In turn the component will notify any listeners that the event has been received and processed. There may be times when you want to intercept or alter the event before it is dispatched to the component. Swing provides a few different approaches that will allow you to control the dispatching of events.
Read the rest of this entry »

Posted in Awt, Swing, Tips | 1 Comment »

Global Event Listeners

Posted by Rob Camick on August 30, 2009

Listeners are used to listen for specific events on a given component. This makes it easy to listen for a MouseEvent on a text component for example. With this approach you need to add a separate listener to the component for every event you want to listen for. However there may be times when you want to listen for events at a more global level. That is, you may want to listen for events:

  • of multiple types on a specific component – in this case you would need to create multiple listeners to add to the component.
  • of a single type on all components – in this case you would need to create a single listener and then recursively add it to all components.

Wouldn’t it be nice if the above requirements could be handled by a single listener?
Read the rest of this entry »

Posted in Awt, Swing, Tips | 13 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 | 24 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 | 21 Comments »

Moving Windows

Posted by Rob Camick on June 14, 2009

Over the years I’ve seen many questions asking about borderless windows. The common suggestion is to use a JWindow or an undecorated JFrame, depending on the requirements. Often you will then find a follow up question asking how to move the window now that there is no title bar. The common answer is that you need to add your own listeners to handle the dragging of the window.
Read the rest of this entry »

Posted in Awt, Classes | 49 Comments »

Visual Font Designer

Posted by Darryl Burke on November 30, 2008

New in version 2: VisualFontDesigner can now be used as a Font chooser, much on the lines of JColorChooser

When trying to create an attractive Font, the first challenge is usually to research the difference that applicable attributes make to its appearance. Applying and reviewing numerous combinations of attributes can be a tedious exercise.

VisualFontDesigner makes it a breeze to quickly visualize the effects of most of the available attributes, with the added bonus of generating a code block that can be directly copied to recreate the font elsewhere.

Read the rest of this entry »

Posted in Application, Awt | 4 Comments »