java 获取窗口id,在java swing中创建X窗口(X11)并获取其id

本文指导如何在Eclipse中使用Java Swing创建X11窗口,并提供获取窗口ID的方法。重点介绍了使用C++通过JNI接口操作,以及解决XFetchName内存泄露问题。递归函数搜索特定窗口名是关键部分。
摘要由CSDN通过智能技术生成

Can anyone help me in creating an X11 window in java swing using eclipse?And also the function to get the x11 id also.What are the basic requirement for creating an X11 window in java.

解决方案

Tom answered the first part of your question. The second part of the answer is: to get the id of an X11 window you are going to have to use native code (code written in C or C++) and access it through the JNI interface.

You may have to run a search by title through all existing windows to get the one you desire.

Here is a recursive function that will search (starting from the root window) for a window with the desired name

Window windowWithName(Display *dpy, Window top, char *name)

{

Window *children, dummy;

unsigned int nchildren;

unsigned int i;

Window w = 0;

char *window_name;

if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))

return (top);

if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))

return (0);

for (i = 0; i < nchildren; i++)

{

w = windowWithName(dpy, children[i], name);

if (w)

break;

}

if (children)

XFree((char *) children);

return (w);

}

Note: **unfortunately there is a well documented memory leak in the XFetchName function implemented in X11 that was never fixed. If you run valgrind and have minor memory leak issues this is whats causing them.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值