Dec 08

The PrinterJob class supports displaying a print dialog for the user to use to select printer settings as shown in the following example.

PrinterJob job = PrinterJob.getPrinterJob();
PageFormat format = job.defaultPage();

// Display print dialog

if (job.printDialog()) {

    // We can now check the settings specified by user

    PrintService selectedPrinter = job.getPrintService();

    // or print something using the settings

    job.setPrintable(myPrintable, job.defaultPage());
    job.print();
}

written by objects \\ tags: , , ,

Dec 07

Creating a test certificate and signing your jar just involves three simple commands. Following shows the commands needed to firstly create your test certificate and add the certificate (with an alias of myCertAlias) to a keystore (named myKeyStore).


keytool -genkey -keystore myKeyStore -alias myCertAlias
keytool -selfcert -keystore myKeyStore -alias myCertAlias

The above only needs to be done once.
You can then use the keystore to sign your jar using the following command.


jarsigner -keystore myKeyStore jarfile.jar myCertAlias

written by objects \\ tags: , , , , , ,

Dec 02

We’ve all seen characters in our text being displayed with squares or questions marks instead of the expected character. Reason for this is the font being used does not include glyphs for the character(s) found in the string.

To display chinese (or any language) text requires a font that supports the characters used by the language. The Font classes canDisplayUpTo() method tests whether that Font is capable of displaying all the characters in a given string.

    	Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    	
    	// The chinese text we will use to test
    	
    	String sample = "\u4e00";    // unicode encoding
    	
    	// Loop for each available font
    	
    	for (int j = 0; j < allFonts.length; j++) {
    		
    		// Test if the font can display the sample text
    		
    	    if (allFonts[j].canDisplayUpTo(sample) == -1) { 
    	        System.out.println(allFonts[j].getFontName());
    	    }
    	}

written by objects \\ tags: , , , ,