请问怎样让一个窗口总是显示在屏幕的最前面? VC 里设置窗口属性就可以做到JAVA 就不知道了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试这个this.setUndecorated(true); 好像没什么方便得方法。可以开另外一个线程,让它每隔多少毫秒调用this.setFront()方法(好像叫setFront,还是toFront?忘了,呵呵,你试一下,应该有效)未测试 我需要的是象超级解霸视屏窗口的On Top效果。 Java的窗口在Windows平台上会以窗口的全路径类名注册窗口类,例如alwaysontop包中的Console(Frame类的子类)会以 alwaysontop.Console注册窗口类,基于这个就可以使用JNI实现Always on top了,以下是相关代码JNI C++中实现代码// CppExtention.cpp : Defines the initialization routines for the DLL.///////////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "CppExtention.h"#include "alwaysontop_CppExtention.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// Message map/////////////////////////////////////////////////////////////////////////////BEGIN_MESSAGE_MAP(CCppExtentionApp, CWinApp) //{{AFX_MSG_MAP(CCppExtentionApp) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CCppExtentionApp construction/////////////////////////////////////////////////////////////////////////////CCppExtentionApp::CCppExtentionApp(){}/////////////////////////////////////////////////////////////////////////////// The one and only CCppExtentionApp object/////////////////////////////////////////////////////////////////////////////CCppExtentionApp g_CppExtentionApp;JNIEXPORT jboolean JNICALL Java_alwaysontop_CppExtention_cppSetOnTop(JNIEnv* pEnv, jclass jClass, jstring jWndClass, jboolean jIsOnTop){ wchar_t* cstr=(wchar_t*)(*pEnv).GetStringChars(jWndClass,NULL); int size=(*pEnv).GetStringLength(jWndClass); CString wndClass=CString(cstr,size); BOOL isOnTop=TRUE; // Set on top HWND hJavaWnd = FindWindow(wndClass,NULL); if(hJavaWnd) { SetWindowPos(hJavaWnd, jIsOnTop ? HWND_TOPMOST : HWND_TOP ,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE); return TRUE; } return FALSE;} 在Java程序中package alwaysontop;public class CppExtention{ private static native boolean cppSetOnTop(String windowClass,boolean isOnTop); static { System.loadLibrary("CppExtention"); } public static boolean setOnTop(String windowClass,boolean isOnTop) { return cppSetOnTop(windowClass,isOnTop); }} package alwaysontop;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Console extends JFrame{ JPanel mPnlContent; public Console() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { mPnlContent = (JPanel) this.getContentPane(); mPnlContent.setLayout(new BorderLayout()); this.setSize(new Dimension(400, 300)); this.setTitle("Always On Top Demo"); } protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public static void main(String[] args) { try { // Set look & feel UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // Validate Console frame=new Console(); frame.validate(); //Center the window Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize=frame.getSize(); if(frameSize.height>screenSize.height) { frameSize.height=screenSize.height; } if(frameSize.width>screenSize.width) { frameSize.width=screenSize.width; } frame.setLocation((screenSize.width-frameSize.width)/2, (screenSize.height-frameSize.height)/2); frame.setVisible(true); boolean b=CppExtention.setOnTop("alwaysontop.Console",true); } catch(Exception e) { e.printStackTrace(); } }} 关于菜单点击没反应 如何遍历二维动态数组,生成所有可能的拼装结果? 在jbuilder9中,无法import java.servlet.*,在提示中没有servlet这个包 一个关于文件上传的问题 急,麻烦各位帮我看看,立马给分! Jbuilder的问题 从PB到JAVA的困苦 java菜鸟提问,一个简单得不得了的,不能再简单的输出问题!!!! 这有一道题,请教大家 求大神帮忙看看这个问题,报错可能的原因及解决办法 析取数组里的值...然后分别排列?各位高手快来帮忙啊! java thread正常中止的问题:run()中的代码一直在执行,如果中止?
this.setUndecorated(true);
可以开另外一个线程,让它每隔多少毫秒调用this.setFront()方法(好像叫setFront,还是toFront?忘了,呵呵,你试一下,应该有效)
未测试
// CppExtention.cpp : Defines the initialization routines for the DLL.
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CppExtention.h"
#include "alwaysontop_CppExtention.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Message map
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CCppExtentionApp, CWinApp)
//{{AFX_MSG_MAP(CCppExtentionApp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CCppExtentionApp construction
/////////////////////////////////////////////////////////////////////////////
CCppExtentionApp::CCppExtentionApp()
{
}/////////////////////////////////////////////////////////////////////////////
// The one and only CCppExtentionApp object
/////////////////////////////////////////////////////////////////////////////
CCppExtentionApp g_CppExtentionApp;JNIEXPORT jboolean JNICALL Java_alwaysontop_CppExtention_cppSetOnTop(JNIEnv* pEnv, jclass jClass, jstring jWndClass, jboolean jIsOnTop)
{
wchar_t* cstr=(wchar_t*)(*pEnv).GetStringChars(jWndClass,NULL);
int size=(*pEnv).GetStringLength(jWndClass);
CString wndClass=CString(cstr,size);
BOOL isOnTop=TRUE; // Set on top
HWND hJavaWnd = FindWindow(wndClass,NULL);
if(hJavaWnd)
{
SetWindowPos(hJavaWnd, jIsOnTop ? HWND_TOPMOST : HWND_TOP ,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
return TRUE;
} return FALSE;
}
package alwaysontop;public class CppExtention
{
private static native boolean cppSetOnTop(String windowClass,boolean isOnTop);
static
{
System.loadLibrary("CppExtention");
} public static boolean setOnTop(String windowClass,boolean isOnTop)
{
return cppSetOnTop(windowClass,isOnTop);
}
}
import java.awt.event.*;
import javax.swing.*;public class Console extends JFrame
{
JPanel mPnlContent; public Console()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
} private void jbInit() throws Exception
{
mPnlContent = (JPanel) this.getContentPane();
mPnlContent.setLayout(new BorderLayout());
this.setSize(new Dimension(400, 300));
this.setTitle("Always On Top Demo");
} protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
} public static void main(String[] args)
{
try
{
// Set look & feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // Validate
Console frame=new Console();
frame.validate(); //Center the window
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=frame.getSize();
if(frameSize.height>screenSize.height)
{
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width)
{
frameSize.width=screenSize.width;
}
frame.setLocation((screenSize.width-frameSize.width)/2, (screenSize.height-frameSize.height)/2);
frame.setVisible(true);
boolean b=CppExtention.setOnTop("alwaysontop.Console",true);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}