SWING / NOTES</>↗Swing01 Aug 2007
The code snippet below describe how we can obtain the available look and feel in the current Swing platform. This information can then be made available to the user, so they can change to look and feel of the application in their preferences. package org.kodejava.swing; import javax.swing.UIManager; public class AvailableLookAndFeel { public static void main(String[] […]
SWING / NOTES</>↗Swing31 Jul 2007
To change JTextField text to upper case can be easily done by adding a DocumentFilter to the JTextField component using the setDocumentFilter() method. The DocumentFilter allow us to filter action for changes in the document such as insert, replace and remove. The code snippet below show us how to do it. package org.kodejava.swing; import javax.swing.JFrame; […]
SWING / NOTES</>↗Swing29 Jul 2007
In this small Swing code snippet we demonstrate how to use java.awt.event.KeyAdapter abstract class to handle keyboard event for the JTextField component. The snippet will change the characters typed in the JTextField component to uppercase. A better approach for this use case is to use the DocumentFilter class. See the following code snippet How do […]
SWING / NOTES</>↗Swing26 Jul 2007
This code snippet demonstrates how to change a JFrame image icon using the setIconImage() method. package org.kodejava.swing; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.WindowConstants; import java.awt.Dimension; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; public class FrameIconExample extends JFrame { public static void main(String[] args) { FrameIconExample frame = new FrameIconExample(); frame.setDe...
CORE API / NOTES</>↗Core API23 Jul 2007
In the previous example, How do I read user input from console using Scanner class?, we use the java.util.Scanner class to read user input. In this example we use another new class introduced in the Java 1.6, the java.io.Console class. The Console class provide methods like readLine() and readPassword(). The readPassword() method can be used […]
CORE API / NOTES</>↗Core API22 Jul 2007
In JDK 1.5 a java.util.Scanner class was introduced to handle user input in console application. This class enable us to read string, integer, long, etc. package org.kodejava.util; import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Read string input for username System.out.print("Username: "); String username = […]