Home » Desktop Java » awt (page 10)

awt

Drag and Drop example

In this tutorial we are going to see how to build a simple application that performs drag and drop operations in a Java Desktop Application. As you know the drag and drop operation is very important in an Application that has to deal with graphical objects. In short, in order to add drag and drop functionality to your application you ...

Read More »

Getting and setting text on the system clipboard

With this example we are going to see how to get and set the text on the system clipboard. This is a very common feature that we all use every day when working on a computer. The most common use of this is when we perform text copy/paste operations. Using this example you can embed this operations in you own ...

Read More »

Focus listener example

This is an example that discusses how to use FocusListener in Java. This is a very handy feature when you have several components and you want to monitor and handle the event when on of them gains or looses focus. In short, all you have to do in order to work with a FocusListener is: Create a new FocusListener Override the methods that correspond to ...

Read More »

Setting the initial focus component in a Window

With this example we shall show you how to set the component that gets the focus when your application starts up. This is very useful when you have many graphical objects firing up at the start up of your application. Let’s see the code snippet that follows and it should be pretty clear:           package com.javacodegeeks.snippets.desktop; ...

Read More »

Prevent an Application Window or Component from gaining focus

With example we are going to see how to prevent a window and a graphical object from gaining focus in a Java Desktop Application. This is very simple, as the only thing you have to do is: Call setFocusable(false) to prevent a component from gaining focus. Call setFocusableWindowState(false) to prevent a window from gaining focus. Call getCurrentKeyboardFocusManager().clearGlobalFocusOwner() to remove the ...

Read More »

Hide Frame when closed example

With this example we are going to see how to hide a closed frame. To do that all you have to do is: Create a new WindowAdapter instance. Override windowClosing method. Now every time a the window closes this method will fire up. Use Frame.setVisible(false) to hide the frame you want.       Let’s see the code: package com.javacodegeeks.snippets.desktop; ...

Read More »

Exit application when Frame is closed example

With this tutorial we shall show you how to exit from your application when a frame is closed. This is a very common use for most GUI applications. This is very easy to do, all you have to do is: Create a new WindowAdapter instance. Override windowClosing method to customize the handling of that specific event. Now every time a ...

Read More »

Set a clipping area from a Shape example

In this example we shall show you how to set a clipping area from a component, in this case an image. This is a very basic operations that you will need when you are working in Java desktop applications that have rich graphcis. Basically all you have to do in order to set a clipping aread from a shape is: ...

Read More »

Stroking or Filling with a Texture example

With this example we shall show you how stroke or fill a simple graphic component with a texture. You might use these to enrich your application with graphics and customize them according tou your own taste In short, in order to fill an image with a texture, one should follow these steps: Create a new ImageObserver instance to monitor the ...

Read More »