Java Thread – Executor framework, Timer and TimerTask

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , with 4 Comments on Java Thread – Executor framework, Timer and TimerTask

Tutorial and example of Executor framework, Timer and TimerTask over Thread

With the Thread class you could create your own timer class using the Thread.sleep(T) method to delay action for some time . This approach, however, has some drawbacks. For periodic events, if the processing times in between the sleep periods vary significantly, then the overall timing will mismatch. Also, if you need many timer events, the program will require many threads and use up system resources.

We can create a Timer functionality withExecutor frameworks and also there is Timer and Timertask available in java.util package. We will see both methods to create Timer functionality. Continue reading “Java Thread – Executor framework, Timer and TimerTask”

XML Tree Viewer using SAX Parser in JAVA with Jtree,JFileChooser component of Swing

XML Tree Viewer using SAX Parser in JAVA with Jtree,JFileChooser component of Swing, How to refresh Jtree when content changes , Expand or collapse JTree

I am going to create a utility application in JAVA for reading the XML document using SAX parser. The application will look like:

XML Tree Viewer using SAX Parser in JAVA
XML Tree Viewer using SAX Parser in JAVA

Continue reading “XML Tree Viewer using SAX Parser in JAVA with Jtree,JFileChooser component of Swing”

JDBC Example with Microsoft Access in Swing, Next and Previous navigation

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , , with 27 Comments on JDBC Example with Microsoft Access in Swing, Next and Previous navigation

JDBC – Java Database Connectivity example in Swing

To use below example, create a DSN name of “ShivaEvening“, which point the Microsoft access database file provided in this article.

Download below files:

JDBCAllinOne.java

Employee.mdb

Code:
Java Database Connectivity -  JDBC

Continue reading “JDBC Example with Microsoft Access in Swing, Next and Previous navigation”

setBackground not working in Swing or AWT

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , , with Leave a comment on setBackground not working in Swing or AWT

setBackground() not working for the JLabel control in JAVA

I tried to change the background color of the JLabel control.

I tried lots of time, gone through JAVA documentation but it doesn’t helped much. After digging i found that few controls in JAVA have transparent background color and therefore controls having transparent background does not work for the setBackground() property.

To set the background color of such controls, we need to explicitly set the Opaque to true.

JLabel lblMousePointer.setBackground(Color.white);
lblMousePointer.setOpaque(true);

setBounds method not working

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , , with Leave a comment on setBounds method not working

SetBounds method of Swing and AWT controls are not working

While working on Swings and AWT, i used the setBounds(int x,int y,int width,int height) method of control as per API documentation.
However soon i realized that this method is not working as per expected.
After few try i found that setBounds() method only works if the Layout of container of control is null.

The layout of the container can be set null like below code:

frame.getContentPane().setLayout(null);