JFrame parent;//这是主窗口
JDialog dialog=new JDialog(parent,true);这样就可以满足你的要求.

解决方案 »

  1.   

    兄弟
    我的问题是主程序是vb做的,它bat文件叫起一个java做的frame,现在需要让vb的窗体失去焦点
    也就是其他任何应用都得不到焦点,应该肯定要调用windows dll
    怎么解决
    救命啊
      

  2.   

    你说的这是进程之间同步执行的问题,代码如下:(VB)Option ExplicitConst INFINITE                   As Long = -1&
    Const STATUS_WAIT_0              As Long = &H0
    Const WAIT_OBJECT_0              As Long = STATUS_WAIT_0
    Const NORMAL_PRIORITY_CLASS      As Long = &H20&Private Type PROCESS_INFORMATION
        hProcess    As Long
        hThread     As Long
        dwProcessID As Long
        dwThreadID  As Long
    End TypePrivate Type STARTUPINFO
        cb              As Long
        lpReserved      As Long
        lpDesktop       As Long
        lpTitle         As Long
        dwX             As Long
        dwY             As Long
        dwXSize         As Long
        dwYSize         As Long
        dwXCountChars   As Long
        dwYCountChars   As Long
        dwFillAttribute As Long
        dwFlags         As Long
        wShowWindow     As Integer
        cbReserved2     As Integer
        lpReserved2     As Long
        hStdInput       As Long
        hStdOutput      As Long
        hStdError       As Long
    End TypePrivate Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function InputIdle Lib "user32" Alias "WaitForInputIdle" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function CloseHandle Lib "Kernel32" (ByVal hObject As Long) As Long
    Private Declare Function CreateProcessA Lib "Kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As LongPrivate Sub Command1_Click()
        SyncShell "D:\ProgramsExample\DelphiExample\stk\Stk.exe"
    End SubPublic Function StartProcess(CommandLine As String, Optional Hide As Boolean = False) As Long
        Const STARTF_USESHOWWINDOW As Long = &H1
        Const SW_HIDE As Long = 0
        
        Dim proc As PROCESS_INFORMATION
        Dim Start As STARTUPINFO    'Initialize the STARTUPINFO structure:
        Start.cb = Len(Start)
        If Hide Then
            Start.dwFlags = STARTF_USESHOWWINDOW
            Start.wShowWindow = SW_HIDE
        End If
        'Start the shelled application:
        CreateProcessA 0&, CommandLine, 0&, 0&, 1&, _
            NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc    StartProcess = proc.hProcess
    End FunctionPublic Function SyncShell(CommandLine As String, Optional Timeout As Long, _
        Optional WaitForInputIdle As Boolean, Optional Hide As Boolean = False) As Boolean    Dim hProcess As Long    Const STARTF_USESHOWWINDOW As Long = &H1
        Const SW_HIDE As Long = 0
        
        Dim ret As Long
        Dim nMilliseconds As Long    If Timeout > 0 Then
            nMilliseconds = Timeout
        Else
            nMilliseconds = INFINITE
        End If    hProcess = StartProcess(CommandLine, Hide)    If WaitForInputIdle Then
            'Wait for the shelled application to finish setting up its UI:
            ret = InputIdle(hProcess, nMilliseconds)
        Else
            'Wait for the shelled application to terminate:
            ret = WaitForSingleObject(hProcess, nMilliseconds)
        End If    CloseHandle hProcess    'Return True if the application finished. Otherwise it timed out or erred.
        SyncShell = (ret = WAIT_OBJECT_0)
    End Function
      

  3.   

    不行
    我的要求其实就可以像QQ开启时输入密码的窗体一样
    尽管其他窗口可以打开,但QQ窗体总是在最前面
      

  4.   

    feng8208(人是铁饭是钢) 
     兄弟:
      你要快啊
      下个星期一之前,我们的项目要结了,不然我挂了。
       我的email:[email protected]
      在此先行谢过!
      

  5.   

    把你要打开的窗口设为模态就可以!
    (JFrame) abc.setModal(true);
      

  6.   

    可以的,我以前还做过,记不太清了,你查查Swing方面的API,好像很简单!
      

  7.   

    用纯Java不能实现,Java的模态窗体只能对自己本身的母窗体有效,如果运行了很多别的程序,Java自己是没有办法总是排在最前列。
      

  8.   

    大兄弟, 我用了这么长时间电脑还没见过这样的程序...
    Always On Top 也只是显示在最前方
    全屏模式也能用 Alt + Esc 切换出来
    从来没见过有程序能霸占着整个操作系统不让往别的程序切换的例子
    也许是我孤陋寡闻, 个人感觉没法实现不过你可以用GUI全屏模式试试看, 但是这样只能达到部分效果
      

  9.   

    这里有一个权宜之计final JFrame frame = new JFrame("Frame");
    frame.addWindowListener(new WindowAdapter(){  
        public void windowDeactivated(WindowEvent e)  {    
            frame.setState(JFrame.ICONIFIED);    
            frame.toFront();    
            frame.setState(JFrame.NORMAL);  
        }
    }引自:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=121761&message=319301
      

  10.   

    这么霸道在windows界面下的确没有见过
      

  11.   

    可能我的意思有点没表达正确
    是这样的
    主程序是vb写的,它呼叫一个java的frame
    然后就是需要java的frame总是在顶层c函数我已经找到了,它是接收一个窗口句柄CWnd ,它能将窗口置顶,就是不知道怎么用
    是否要将java的frame对象传入c函数,但是java的frame对象怎么样转化成c函数需要的CWnd 类型
    或者是根本不用转化函数是我到vc那去问来的:

    如何使窗口始终在最前方?
    两种途径.
    BringWindowToTop(Handle);
    SetWindowPos函数,指定窗口的 最顶风格,用WS_EX_TOPMOST扩展窗口的 风格
    Example:
    void  ToggleTopMost( CWnd *pWnd)
    {
             ASSERT_VALID(pWnd);
             pWnd ->SetWindowPos(pWnd-> GetStyle( ) &WS_EX_TOPMOST)?
                  &wndNoTopMOST: &wndTopMost,0,0,0,0,SSP_NOSIZE|WSP_NOMOVE);
    }

    靠各位了
      

  12.   

    能不能在主程序中设置一BOOLEAN变量,控制焦点FOCUS的转移……
      

  13.   

    我上面的回复连接里面有 Always On Top 的解决方法
    http://forum.java.sun.com/thread.jsp?forum=57&thread=121761&message=319301
    其他情况就得另待高人了...