A New Jersey judge apologized after he suggested a woman sell naked photos of herself to Hugh Hefner during a court proceeding involving alleged revenge porn and an extramarital affair.

Middlesex County Assignment Judge Alberto Rivas admitted multiple violations of the Code of Judicial Conduct and said his comments were inappropriate, according to documents released Thursday. Rivas is the subject of a complaint filed with the Advisory Committee on Judicial Conduct over his handling of the case.

The judge’s comments came as he presided over a dispute involving the girlfriend of a married man and his wife. The girlfriend sought to have her boyfriend’s wife return what she claimed where explicit photos of herself purportedly held by the wife. The girlfriend also alleged her paramour’s wife sent the photos to her work and feared she would share them on social media.

Rivas, however, doubted the girlfriend’s allegations, according to court papers. The judge found the claim was actually an attempt to harm and embarrass the man’s wife, calling it a “complete fabrication.”

“I regret the comments I made during the proceeding,” Rivas said in a statement released by court officials. “I felt the court was being manipulated, but I let my feelings about the case influence my language, tone and demeanor, all of which were inappropriate.”

Among the comments at issue in the complaint, were a series of questions casting doubt on the girlfriend’s claim she didn’t know where the wife worked.

“Baloney. That’s not true. If you’re screwing him -- let’s be frank now, because I should not be wasting judicial resources on this kind of malarkey. If you have been screwing him for these years, there’s no question that you know where she works. That’s how affairs work. This is not someone you just met,” the judge said at the hearing, according to court documents.

Rivas also said, “I will give you a piece of advice...The only person you should be sending naked pictures to are (sic) Hugh Hefner. He will pay you $100,000 for the use of them,” the complaint stated.

Documents also described the judge asking the man’s wife why she did not divorce her husband, who was a corrections officer. People in the case were not publicly named in the documents.

“I would suggest divorce, and take half his pension. That’s an option you have, having sat in Family Court,” Rivas told her. “You can take his pension.”

At another point in the proceeding, the judge turned his ire on the husband, who was in the courtroom but not a party to the case.

“I wish you were up here, because I’m gunning for you, because you are despicable,” the judge told the husband, filings in the matter said.

The complaint alleged the judge “compromised both his integrity and impartiality and that of the Judiciary,” and “...impugned the integrity of the Judiciary and demonstrated an inability to conform his conduct to the high standards of conduct expected of judges,” documents said.

In suggesting the wife “take half” the husband’s pension in court, the judge created the appearance of bias, according to the complaint.

For his part, Rivas said in a response to the complaint that his comments were not borne from “family, social, political, financial or other relationships or interests.” Instead, he said he was responding to a “bad faith” allegation from the girlfriend and not bias or prejudice.

In a statement, the state Administrative Office of Courts said a formal hearing would be scheduled in the judge’s case.

Noah Cohen may be reached at ncohen@njadvancemedia.com. Follow him on Twitter @noahyc. Find NJ.com on Facebook.

Have a tip? Tell us. nj.com/tips