如何使用X11和Java查找Windows的标题文本 [英] How to Find Title Text of Windows using X11 with Java

查看:202
本文介绍了如何使用X11和Java查找Windows的标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个窗口的焦点更改为另一个窗口。我在Windows中完成了这项任务,现在我想使用X11为Linux / Ubuntu操作系统执行相同的任务..



假设我们已经打开了两个应用程序



运行时运行= Runtime.getRuntime();

进程prog = run.exec(gedit);

流程prog2 = run.exec(gcalctool);




如果当前的焦点窗口是计算器,则窗口的焦点变为文本编辑器,反之亦然。





嗨专家帮助...



提前致谢



问候

Nei Sa

解决方案

  / /  运行时运行= Runtime.getRuntime(); //那是静态的东西,请不要实例化。 


Runtime.getRuntime()。exec( gedit);
Runtime.getRuntime()。exec( gcalctool);





这些命令正在执行应用程序。

这些命令不会改变焦点。

唯一原因计算器在文本编辑器前面的原因是它最后被激活了。


我似乎无法找到任何可以导入Java的库允许在Linux上切换窗口。



您可以做的是创建一个shell脚本来为您完成工作,并从您的Java应用程序中调用该shell脚本。用户需要安装wmctrl。

http: //askubuntu.com/questions/21262/shell-command-to-bring-a-program-window-in-front-of-another [ ^ ]



如果您的应用程序需要在Windows和Linux上运行,您可以运行检查以查看运行该应用程序的操作系统。

 System.getProperty(  os.name



至于shell脚本,你可以试试这样的东西。我还没有测试过,因为我无法访问Linux系统。 codeproject也不支持shell脚本代码,所以我希望这段代码是可读的。



#!/ bin / bash

parameter1 =


1

wmctrl -a parameter1



在Java应用程序中,您可以像这样调用此脚本:

处理focusGedit =  new  ProcessBuilder(  path / to / script   gedit)。start(); 


I want to Change focus of One window to another window. I have done this task in Windows and now I want to do same task for the Linux / Ubuntu OS using X11..

Suppose we have opened two applications

Runtime run = Runtime.getRuntime();
Process prog = run.exec("gedit");
Process prog2 = run.exec("gcalctool");


if current focused window is Calculator then Window's focus changed to the text Editor or vice versa.


Hey Experts Help...

Thanks in Advance

Regards
Nei Sa

解决方案

//Runtime run = Runtime.getRuntime(); // That's static stuff, please do not instance it.


Runtime.getRuntime().exec("gedit"); 
Runtime.getRuntime().exec("gcalctool"); 



Those commands are executing apps.
These commands do NOT change focus.
Only reason Calculator is in front of Text Editor is that it got activated last.


I can't seem to find any library that you can import into Java to allow window switching on Linux.

What you can do is create a shell script to do the work for you and just call that shell script from your java application. The user needs "wmctrl" installed though.
http://askubuntu.com/questions/21262/shell-command-to-bring-a-program-window-in-front-of-another[^]

If your application needs to run on both Windows and Linux you can run a check to see what OS the application is running in.

System.getProperty("os.name")


As for the shell scrip, you can try something like this. I haven't tested it yet as I don't have access to a Linux system. Also codeproject does not support shell scrip code so I hope this code will be readable.

#!/bin/bash
parameter1 =


1
wmctrl -a parameter1

In your Java application you can call this script like this:

Process focusGedit = new ProcessBuilder( "path/to/script", "gedit").start();


这篇关于如何使用X11和Java查找Windows的标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆