Home » Desktop Java

Desktop Java

Determine format of an image

With this tutorial we are going to see how to determine the format of an image in a Java Desktop Application. You will find this particularly useful in applications that need to process large numbers of images. Additionally you can use these for input verification. In short, to determine the format of an image all you have to do is: ...

Read More »

List read/write supported image formats

This is an example on how to list read/write image formats in a Java Desktop applications. You can find this very useful when you want to create “Help” tooltip list with all the supported image files to inform the user. You can also use it for input validation. Basically, in order to list read/write image formats, you should: Create a ...

Read More »

Read image from file

In this tutorial we are going to see how to read an image from a file. This is very useful when you want to store image files in your system and you want to use them to enrich the graphics of your application. In order to read image from a file: You have to open a new File in the ...

Read More »

Create image file from graphics object

With this tutorial we shall show you how to create an image file from graphics object. This is particularly useful when you want to create your own images out of custom made graphics. Creating an image file from graphics object requires that you: Create a new BufferedImage. Create a Graphics2D using createGraphics. Create a new File("myimage.png"). Use ImageIO.write(bufferedImage, "jpg", file) ...

Read More »

Compress a JPEG file

With this example we are going to learn how to compress a JPEG file. When saving space is important for your system, you have to consider compressing your images using JPEG format. This format compresses the image but its high quality can be preserved. In order to compress a JPEG file all you have to do is: Open a new ...

Read More »

Handle print service attribute changes

In this example we are going to see how to handle print services attributes changes in a Java Desktop Applications. This will give you more control when handling print jobs inside your application. To handle print service attribute changes one should take these steps: Use PrintServiceLookup.lookupDefaultPrintService() to locate the default print service for this environment. Create a class that implements ...

Read More »

Handle print job attribute changes

In this example we are going to see how to handle print job attributes changes in a Java Desktop Applications. This will give you more control when handling print jobs inside your application. To handle print service attribute changes one should take these steps: Use PrintServiceLookup.lookupDefaultPrintService() to locate the default print service for this environment. Create a class that implements PrintJobAttributeListener. Override attributeUpdate method to ...

Read More »

Set orientation for print job

With this tutorial we are going to learn how to set orientation for print jobs in a Java Desktop Application. This is a very basic feature, if you want to offer print services inside your application, because it gives the user the ability to choose the orientation of his printing. In order to set orientation for print jobs you simply ...

Read More »

Set copies number for print job

This is an example on how to set copies number for print jobs in your Java Desktop Application. In order to do that, one should follow these steps: Open a new pdf file to print using BufferedInputStream(new FileInputStream("myfile.pdf")). Create a PDF doc flavor using DocFlavor.INPUT_STREAM.PDF that returns aDocFlavor object. Use PrintServiceLookup.lookupDefaultPrintService() to locate the default print service for this environment. Use createPrintJob() to create and return a DocPrintJob capable of ...

Read More »

Print to file with Java

In this example we are going to see how to print a document to a .ps file in Java. This is very useful when you want to create simple and easy previews of the print that the user might perform. In order to print to a file, one should follow these steps: Open a new pdf file to print using BufferedInputStream(new ...

Read More »