Java Jframe launch another JFrame to another X Server

房东的猫 提交于 2019-12-11 09:57:49

问题


I have java application which is runs on Xvnc (on Ubuntu) screen (DISPLAY :1), what I need to do is, to launch another JFrame to main screen DISPLAY :0 from one application, that is, the one running in DISPLAY :1.

I have think about using Runtime.getRuntime().exec(), but the problem is, i need to control the second JFrame properties from the main application.

Please help on how can I achieve that. Thank you. I don't need cross platform solution, just for ubuntu.

UPDATE:

i used code

try{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gd = ge.getScreenDevices();
    for(int i = 0; i < gd.length; i++){
        System.out.println(gd[i]);
    }
} catch (Exception e){
    e.printStackTrace();
}

And i only get one display X11GraphicsDevice[screen=0], meaning that GraphicsDevice[] gd = ge.getScreenDevices(); only have 1 device. My XVNC X11 server (DISPLAY :1) does not detected.


回答1:


Here is how to set a frame to a display
Make this instance data for class:

public class Graphic{
 private GraphicsEnvironment graphicsEnviorment;
 private DisplayMode dm, dm_old;
 private    JFrame frame1=new JFrame(), frame2 =new JFrame(); // we now have access to both jframes

public void makeScreen(){
    graphicsEnviorment = GraphicsEnvironment.getLocalGraphicsEnvironment();

    GraphicsDevice[] devices = graphicsEnviorment.getScreenDevices();

    dm_old = devices[0].getDisplayMode(); // replace 0 with screen #
    dm = dm_old;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    //place dead center on screen 
    int windowX = Math.max(0, (screenSize.width - frame.getWidth()) / 2);
    int windowY = Math.max(0, (screenSize.height - frame.getHeight()) / 2);

    frame1.setLocation(windowX, windowY);

             frame1.setVisable(true);
             // frame 2

            dm_old = devices[0].getDisplayMode(); // replace 0 with screen #
    dm = dm_old;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    //place dead center on screen 
    int windowX = Math.max(0, (screenSize.width - frame.getWidth()) / 2);
    int windowY = Math.max(0, (screenSize.height - frame.getHeight()) / 2);
    frame2.setLocation(windowX, windowY);

             frame2.setVisable(true);

            }
}

Now use observer platform (listeners) to hand changes between the two frames...




回答2:


Unfortunatly TheBetaProgrammer solution is to display JFrames on 2 screens of the same display and not on 2 differents displays. I'm looking for the same thing for the last few days and have not found any easy way to do that. So far I'm going to have 2 applications each on it's its own display, talking together using JGroups (I send directly action events between the 2 apps).



来源:https://stackoverflow.com/questions/22840402/java-jframe-launch-another-jframe-to-another-x-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!