SWING / NOTES</>↗Swing23 Nov 2009
The program below demonstrate how to change the default icons of a JTree component. We can change tree icons of the component which are the closed icon, the open icon and the leaf icon. package org.kodejava.swing; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import java.awt.*; import java.util.Objects; public class JTreeChangeIcon extends JFrame { public JTreeChangeIcon() throws […]
SWING / NOTES</>↗Swing21 Nov 2009
You can remove JTree default icons by modifying the tree cell renderer object. To get the cell renderer call the JTree.getCellRenderer() which will return a DefaultTreeCellRenderer object. Then you can remove the icon by setting a null value to the setLeafIcon(), setClosedIcon() and setOpenIcon(). package org.kodejava.swing; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import java.awt.*; public […]
CORE API / NOTES</>↗Core API17 Nov 2009
To sort the elements of LinkedList we can use the Collections.sort(List<T> list) static methods. The default order of the sorting is a descending order. package org.kodejava.util; import java.util.LinkedList; import java.util.Collections; public class LinkedListSort { public static void main(String[] args) { LinkedList<String> grades = new LinkedList<>(); grades.add("E"); grades.add("C"); grades.add("A"); grades.add("F"); grades.add("B"); grades.add("D"); System.out.println("...
CORE API / NOTES</>↗Core API16 Nov 2009
The get the first element we can use the LinkedList.getFirst() method and to get the last element we can use the LinkedList.getLast() method. package org.kodejava.util; import java.util.LinkedList; public class LinkedListGetFirstLast { public static void main(String[] args) { LinkedList<String> names = new LinkedList<>(); names.add("Alice"); names.add("Bob"); names.add("Carol"); names.add("Mallory"); // Get the first and the last element of […]
CORE API / NOTES</>↗Core API15 Nov 2009
To reverse the order of LinkedList elements we can use the reverse(List<?> list) static method of java.util.Collections class. Here is the example: package org.kodejava.util; import java.util.LinkedList; import java.util.Collections; public class LinkedListReverseOrder { public static void main(String[] args) { LinkedList<String> grades = new LinkedList<>(); grades.add("A"); grades.add("B"); grades.add("C"); grades.add("D"); grades.add("E"); grades.add("F"); System.out.printl...
CORE API / NOTES</>↗Core API11 Nov 2009
This program shows you how to use the remove(int index) method of LinkedList class to remove an item at specified index from linked list object. package org.kodejava.util; import java.util.LinkedList; public class LinkedListRemove { public static void main(String[] args) { LinkedList<String> names = new LinkedList<>(); names.add("Alice"); names.add("Bob"); names.add("Carol"); names.add("Mallory"); System.out.println("Original values are:"); System.out.println("===============...