Santa Ana, California (CNN) -- Veteran by veteran, Orange County, California, Superior Court Judge Wendy Lindley is dispensing justice with tough talk and a little cheerleading to the former servicemen who've returned from war in Iraq or Afghanistan. The vets are now convicted civilians in her court.

"Mr. Baker," Lindley asks one veteran, "how long you been sober? About four or five years.... Welcome back to the human race. It's great to have you around here."

"Mr. Culpepper," the judge later addresses another offender, "the report from the Veterans Affairs is excellent.... I am going to continue you on probation on the same terms. Give him a hand, folks."

The gallery offers applause.

Lindley's courtroom is one of as many as 40 "veterans courts" nationwide, a trend initiated two years ago to deal with a growing number of veterans whose criminal offenses were about to put them in prison, officials said.

The veterans courts are part of local trial court systems, and they usually deal with lesser offenses in which the veteran has pleaded guilty and is also dealing with post-traumatic stress disorder, drug addiction, alcoholism or mental-health issues. About 20 percent of Iraq and Afghanistan war veterans suffer post-traumatic stress disorder, according to a 2008 Rand Corporation study.

With assistance from the U.S. Department of Veterans Affairs, the courts offer guidance and case management to help keep convicted veterans out of jail, in exchange for their participation in an intensive probation program.

Lindley calls its "therapeutic justice." The Veterans Affairs agency calls it part of a "veteran justice outreach initiative," which seeks to avoid "the unnecessary criminalization of mental illness and extended incarceration" of veterans. The idea is to rehabilitate offenders with medical and social services.

For example, one veteran, Michael, who served in Army special operations in Afghanistan and lost a leg to a rocket-propelled grenade attack, was pleading guilty to making a death threat.

Instead of sentencing him to three years in jail, Lindley put him on probation and ordered 18 months of supervision and treatment for his post-traumatic stress disorder and problems with drugs and alcohol.

"I think that we have an ethical and moral obligation to try to restore these human beings to who they were before they were brave enough to volunteer and go and try to protect the rights that you and I enjoy every day," said Lindley, whose court accepts only veterans who had clean records before they went to war.

"Are we safer as a community if we simply process these human beings through the system and send them off to prison and have them come back out to our community, because they will come back, to our community?" Lindley added. "And if we have them come back there and their PTSD has not been treated, what's the likelihood that they are going to have another violent act in our community?"

Some defendants have been dealing with thoughts of suicide, the judge said.

"Many of our young men have tried to kill themselves because they are unable to adapt when they return and some of them have such remorse for things that they did in the name of war that are very difficult for them," she said.

It's up to local court administrators to set up and oversee veterans courts, and the number is growing.

Sergio Antoniuk, a social worker with the Veterans Affairs department in Los Angeles, said a new veterans court was scheduled to open Monday, November 1, in Ventura County. The recently opened veterans court in Los Angeles happens to deal more with Vietnam vets.

For those who might question whether the veterans courts create another standard of justice, Antoniuk said the veterans courts are like other specialty courts, such as drug courts.

"There's got to be somebody out there who thinks it's a free ride, but the idea is treatment for mental-health issues, psychiatric care, counseling as well as substance-abuse treatment," said Antoniuk.

"I don't think it's a double standard. It's a more appropriate standard really," he added. "You either treat it or you don't treat it."

Orange County Deputy District Attorney Wendy Brough described veterans court as "a paradigm shift, to go from trying to get the appropriate sentence, which generally is how much jail time ... to more of a rehabilitation."

Veterans expressed gratitude at having a chance to turn their life around -- outside of jail.

"This program has really changed my life. I was beat down pretty hard," said Daniel, a former Marine who faced jail for two drunk-driving convictions. He's now in film school.

"I don't see that me spending six months in county jail ... I don't see how that would have helped me change how I look at my life. I would have just gotten through it and probably reverted back to my old ways," Daniel said.

Another veteran, Shahab, a "graduate" who successfully completed his treatment program, told the judge that he was jobless and "had nothing to live for" when he first came into the courtroom.

His life is different today, he told the judge. Under the program, he found a job working in a mental-health facility.

"You're a godsend," Shahab told the judge. "Seriously, you could be a saint. Nowadays we don't believe in those things, but it's true."

But Lindley isn't afraid to throw a wayward veteran behind bars for a night.

"Don't give me any garbage about how you were in the room and someone else was smoking marijuana because that doesn't cut it," the judge told one veteran who tested positive for drugs.

"I really need you to examine yourself as to why you thought it was a better option to lie than to just own up to it and deal with it," the judge said. The veteran was handcuffed and taken to jail.

"You are going to get an overnight, you'll get out tomorrow at 6 a.m.," the judge told him.