Thursday, February 23, 2012

Setting Maximum no. of characters in jTextField for Swing Application

Sometimes we need to fixed the maximum size of a text field. For this purpose, we need to implement a document containing an overriding function of plain document.

public class MaxLengthTextDocument extends PlainDocument {

private int maxChars;

@Override
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException {
if(str != null && (getLength() + str.length() < getMaxChars())){ super.insertString(offs, str, a); } } /** * @return the maxChars */ public int getMaxChars() { return maxChars; } /** * @param maxChars the maxChars to set */ public void setMaxChars(int maxChars) { this.maxChars = maxChars; } }



after that we will have to set the following line after initComponents() of view file.


MaxLengthTextDocument maxLength = new MaxLengthTextDocument();
maxLength.setMaxChars(12);//50 is a maximum number of character
this.txtMobileNo.setDocument(maxLength);

Wednesday, February 22, 2012

Executing a JAR file using Windows Task Scheduler

Generally, when we click over a jar file , it executes. But if we are in need of executing a jar file using Windows Scheduler it invites some barriers(!).
We are not in need to do something incredible, just usingthe Windows Task Scheduler. . We need to customize the various prefrences for setting up the task in the windows scheduler.

Since a JAR file is not a Windows executable file, all you need to do is:

1. Type task in the run from the start menu(for windows 7).
2. from the action panel of the right side of the window, select Create task.
3. Filling all the parameters of General and Trigger panel, from the action panel
Set program or script to the location of java.exe from the specified location of the jre folder.
C:\Program Files\Java\jre6\bin\java.exe
Set add arguments option to something like the command line to execute the jar.
-jar D:\jarFileLocation\jarFile.jar




Thursday, February 2, 2012

MSDTC on server 'servername' is unavailable

MSDTC on server 'servername' is unavailable

By default, when a stand-alone instance of Microsoft SQL Server exists in a cluster environment, the SQL Server-based instance is set to start automatically. If the host node is rebooted, you may receive the following error message when you issue commands that are related to distributed transactions:

RESOLUTION
On the server where the trigger resides, you need to turn the MSDTC service on. You can this by clicking START > SETTINGS > CONTROL PANEL > ADMINISTRATIVE TOOLS > SERVICES. Find the service called 'Distributed Transaction Coordinator' and RIGHT CLICK (on it and select) > Start.