I want to construct some theorem-type of environment by using package ntheorem. I have edited the following source codes:
\documentclass[A4paper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[amsmath,amsthm,thmmarks]{ntheorem}
\theoremstyle{plain}
\theoremheaderfont{\normalfont}
\theoremseparator{.}
\theorembodyfont{\normalfont }
\theoremsymbol{\ensuremath{\Box}}
\newtheorem{Def}{\bf Definition}
\begin{document}
\begin{Def}
Let $n$ be a positive integer and $\mathbb{K}$ a field. Let $SL_n(\mathbb{K})$ denote the set of special linear group, that is
$$SL_n(\mathbb{K}):=\{M\in\mathbb{K}^{n\times n}\mid |M|=1\}.$$
\end{Def}
\begin{Def}
Let $n$ be a positive integer and $\mathbb{K}$ a field. Let $SL_n(\mathbb{K})$ denote the set of special linear group, that is
$SL_n(\mathbb{K}):=\{M\in\mathbb{K}^{n\times n}\mid |M|=1\}.$
\end{Def}
\begin{Def}
Let $n$ be a positive integer and $\mathbb{K}$ a field. Let $SL_n(\mathbb{K})$ denote the set of special linear group, that is
$$SL_n(\mathbb{K}):=\{M\in\mathbb{K}^{n\times n}\mid |M|=1\}.$$
\vspace{-10ex}
\begin{gather*}
\end{gather*}
\end{Def}
\end{document}
The result is as follows:

As you can see in Definition 1, the QED box dose not occur when the Def environment ends with the $$ ... $$. But when I ends the whole Def environment with just $...$, as in Definition 2, the QED box does occur.
And I tried many ways. Finally, I have found some method to remedy this. That is to modify the vertical space of QED box by the code:
\vspace{-10ex}
\begin{gather*}
\end{gather*}
added before the line of "end\Def". As in Definition 3, this method works. But it is very complex.
Is there any easy way to solve this problem?

special linear group, that isand replace$$with\[...\], I get the box. – Aug 25 '14 at 06:52$$...$$for display mathematics in latex but rather\[...\], see http://tex.stackexchange.com/q/503/15925 . With this change your example will work as expected. – Andrew Swann Aug 25 '14 at 06:57no empty lineat the end — actually no empty line after an end of input inparagraph mode. – Bernard Aug 25 '14 at 08:56