Home » Desktop Java » awt (page 3)

awt

List all available font families

With this tutorial we are going to see how to list all available font families in your environment using Java. A font family refers to a set of font faces with a related typographic design. For example, the font faces in the Lucida Sans Typewriter family are Lucida Sans Typewriter Bold, and Lucida Sans Typewriter Regular etc. This example lists ...

Read More »

Draw mixed style text example

In this tutorial you are going to see how can you draw a line of text that each word has a different style In order to draw mixed style text in Java, all you have to do is: Set the desired font if different from default font using the Font class Use AttributedString to create String that you can work ...

Read More »

Window closing event handling

In this example we are going to see how to handle window closing events. This is a very basic event handling when you are working on a UI Application. Basically all you have to do to handle window closing events is: Create a simple JFrame window Use addWindowListener to add a window listener to the JFrame Override windowClosing method of ...

Read More »

VetoableChangeListener example

With this example you are going to learn about a very important event monitoring component, the VetoableChangeListener. The VetoableChangeListener is , in many ways, similar to the PropertyChangeListener class. The main difference is that PropertyChangeListener is applied to bound properties. On the other hand the VetoableChangeListener is applied to constraint properties. A bound property is just as simple as a property. A ...

Read More »

WindowListener demo

In this tutorial we will see how to use the WindowListener. This is particularly useful when you are working with a window application and you want to monitor the state of each window. With the WindowListener you can monitor a number of events. The opening or the closing of a window for instance. So, when a window opens or closes, ...

Read More »

Display all events occurring in a window

In this example we shall show you how to display all events occurring in a windows. This is very useful when you want to have full control o events that occur in a Java applications that has many windows to handle. It is a very simple ways to manage the activity on your windows. To display all the events that ...

Read More »

Multicast event example

In this tutorial we are going to see how to manage multicast events. Multicast events are quite useful when you have to work with many windows in your application and you just want to perform the same action or a group of actions in a number of windows in your application at the same time. For example, if the user ...

Read More »

Multiple listeners example

In this example we are going to talk about how to work with multiple listeners in Java. This is particularly useful when you want to register more than one listeners in a single component, a button for instance. All you have to do to work with multiple listeners is: Create a class that extends JFrame and implements ActionListener. Create an ...

Read More »

Keymap and KeyStroke example

With this example we are going to see how to use Keymap and KeyStroke classes in a Java. These classes are useful when you want to bind a certain key stroke with the default button of the window. In order to work with Keymap and KeyStroke: Use KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false) method to get the “Enter” key stroke. Use Keymap.removeKeyStrokeBinding to ...

Read More »

Change Event behavior dynamically

In this example we are going to see how to change the behavior of an event dynamically in your Java program. It is very simple to add this kind of functionality in your application. All you have to do is: Create some classes that implement the ActionListener interface. Bundle these ActionListener with a specific button or component using addActionListener method. ...

Read More »