SPRING JDBC / NOTES</>↗Spring JDBC15 Dec 2009
In this example you will learn how to create and configure a DriverManagerDataSource object that will be used by the JdbcTemplate object. There are some information required when creating a DataSource including the JDBC driver class, the JDBC Url of the target database, the username and password for connecting to database server. package org.kodejava.spring.jdbc; import […]
APACHE COMMONS / NOTES</>↗Apache Commons11 Dec 2009
The following example shows you how to read file contents into byte array. We use the IOUtils class of the Apache Commons IO library. package org.kodejava.commons.io; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class FileToByteArray { public static void main(String[] args) { File file = new File("README.md"); try { InputStream is […]
SWING / NOTES</>↗Swing07 Dec 2009
The example below demonstrates you how to create a JTree that have a different icons for each node of the tree. package org.kodejava.swing; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeCellRenderer; import java.awt.*; import java.net.URL; public class JTreeDifferentNodeIcon extends JFrame { public JTreeDifferentNodeIcon() throws HeadlessException { initializeUI(); } public static void main(String[] args) { SwingUtilities.in...
SWING / NOTES</>↗Swing04 Dec 2009
This example demonstrates how to use the expand-all and / or collapse-all features in the java.swing.JTree swing component. package org.kodejava.swing; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import javax.swing.tree.TreeNode; import java.awt.*; import java.util.Enumeration; public class JTreeNodeAutoExpandCollapse extends JFrame { public JTreeNodeAutoExpandCollapse() throws HeadlessException { initializeUI(); } p...
SWING / NOTES</>↗Swing30 Nov 2009
The code below demonstrates how to delete a node from a JTree component. package org.kodejava.swing; import javax.swing.*; import javax.swing.tree.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class JTreeRemoveNode extends JFrame { public JTreeRemoveNode() throws HeadlessException { initializeUI(); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new JTreeRemoveNode().setVisible(true)); } priva...
SWING / NOTES</>↗Swing25 Nov 2009
The following example show how to use the JTree.getSelectionPaths() method to get the selected node of a JTree component. This method returns an array of TreePath objects. In the case to get the last node in the path we can call the TreePath.getLastPathComponent(). In the code below when you pressed the button the listener gets […]