WILMINGTON, Del. (AP) — The judge presiding over a federal cyberstalking trial stemming from a fatal shooting at a Delaware courthouse has granted the government's request to bar the public from the courtroom during testimony by the gunman's granddaughter.

The ruling by Judge Gerald McHugh Jr. came over objections from the media Friday in the trial of former optometrist David Matusiewicz; his mother, Lenore Matusiewicz; and his sister, Amy Gonzalez.

They are accused of conspiracy and cyberstalking of David's ex-wife, Christine Belford, and could face life in prison if convicted. Department of Justice officials have said they are not aware of any previous case in which a defendant was sentenced to life in prison for a cyberstalking conviction that resulted in a victim's death.

David's father, Thomas, killed Belford and a friend at the courthouse in 2013 as they arrived for a child support hearing, then exchanged gunfire with police before killing himself.

Prosecutors say David Matusiewicz conspired with his parents and sister over several years to torment and stalk his ex-wife with the intent to injure, harass, intimidate and kill her, repeatedly accusing Belford in email communications, letters and Internet postings of abusing and neglecting the couple's three daughters.

But Thomas Matusiewicz's family members have denied knowing that he intended to kill Belford.

The shooting followed a bitter custody battle during which David lost his parental rights after he and his mother kidnapped his daughters and took them to Central America in 2007. David Matusiewicz pleaded guilty in 2009 to federal fraud and kidnapping charges. Lenore Matusiewicz served more than a year in Delaware state prison for child endangerment for her role in the kidnapping.

The eldest daughter, now 13, will testify next week against her father, grandmother and aunt.

McHugh said the fact that the defendants joined in the prosecution request to seal the courtroom during the girl's testimony weighed heavily in his decision.

"I find myself at the intersection of competing rights," the judge said, balancing the defendants' rights to a fair trial, including the right to confront witnesses against them, with the First Amendment right of public access to the courts.

McHugh nevertheless ruled that prosecutors had shown a compelling interest in seeking to spare the girl the risk of further psychological trauma by being forced to testify in public. He also noted that a transcript of her testimony will be made available on an expedited basis, and that any redactions he approves will be minimal and only for "extraordinary purposes."

In granting closure of the courtroom, McHugh overruled arguments by an attorney for The Associated Press and the News Journal of Wilmington that the courtroom should remain open, or that the court approve alternative measures. The AP has not named the girl during its coverage of the trial or shown any images of her.

Media attorney David L. Finger suggested that McHugh could arrange for the girl to testify by closed-circuit television or from behind a partition, or allow reporters for the two news organizations in court while excluding other members of the public.

Even without reporters or other members of the public in the court, the girl will be testifying in front of some two dozen strangers, including jurors, attorneys and court staff, Finger noted.

"How many (strangers) is too many?" he asked.

Prosecutor Ed McAndrew said the girl is fearful of being seen in court, and that avoiding undue psychological harm to her is sufficient reason to close the courtroom, as is often done in cases involving child sexual abuse.

Prosecutors have said the Matusiewicz family's stalking of Belford was aimed at reuniting David with his daughters, and that it centered on unsubstantiated accusations that Belford had sexually abused the oldest girl. While prosecutors have asserted that Belford did not physically or sexually abuse her daughter, the judge noted that the girl has "an extraordinary history" and will be testifying about the accusations.

"By definition, she will talk about very sensitive, personal and intimate things," McHugh said.