JDOM / CATATAN</>↗JDOM21 Jan 2010
This example demonstrate how to convert JDOM Document object to a String using the XMLOutputter.outputString(Document doc) method. package org.kodejava.jdom; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; public class JDOMDocumentToString { public static void main(String[] args) { Document document = new Document(); Element root = new Element("rows"); // Creating a child for the root element. […]
CORE API / CATATAN</>↗Core API17 Jan 2010
To look up the default print service we can use the javax.print.PrintServiceLookup class lookupDefaultPrintService() method. package org.kodejava.print; import javax.print.PrintService; import javax.print.PrintServiceLookup; public class GetPrinter { public static void main(String[] args) { // Gets the default print service for this environment. Null is returned when // no default print service found. PrintService service = PrintServiceLookup.lookupDefaultPrintService(); if [...
SWING / CATATAN</>↗Swing12 Jan 2010
The example below demonstrate how to create a custom JTextPane component that have a background image. package org.kodejava.swing; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Objects; public class TextPaneWithBackgroundImage extends JFrame { public TextPaneWithBackgroundImage() { initUI(); } public static void main(String[] args) { SwingUtilities.invokeLater( () -> new...
CORE API / CATATAN</>↗Core API10 Jan 2010
In the following example we are going to sort a string containing the following numbers "2, 5, 9, 1, 10, 7, 4, 8" in ascending order, so we will get the result of "1, 2, 4, 5, 7, 8, 9, 10". package org.kodejava.util; import java.util.Arrays; public class SortStringNumber { public static void main(String[] args) { […]
AWT / CATATAN</>↗AWT05 Jan 2010
The program below show you how to turn on the Scroll Lock button programmatically. Setting the locking state to Boolean.TRUE activate the Scroll Lock. package org.kodejava.awt; import java.awt.*; import java.awt.event.KeyEvent; public class TurnScrollLockOn { public static void main(String[] args) { // Gets the default toolkit. Toolkit toolkit = Toolkit.getDefaultToolkit(); // Update the locking state for […]
AWT / CATATAN</>↗AWT02 Jan 2010
The example below show you how to activate the Num Lock button programmatically. Setting the locking state to Boolean.TRUE will turn the Num Lock on. package org.kodejava.awt; import java.awt.Toolkit; import java.awt.event.KeyEvent; public class TurnNumLockOn { public static void main(String[] args) { // Gets the default toolkit. Toolkit toolkit = Toolkit.getDefaultToolkit(); // Update the locking state […]