[英]Different JFrames on different displays
I have a central database, I connect to it with JDBC and after some preparations with the data, I produce 6 different JFrames, and I like to display each on a different display (monitor) on different walls of the building, which I can reach only over IP (by WiFi) at the same time. 我有一个中央数据库,我用JDBC连接到它,经过一些数据准备后,我生成了6个不同的JFrame,并且我希望将它们分别显示在建筑物不同墙壁上的不同显示器(监视器)上。仅同时通过IP(通过WiFi)。 Can I solve it with GraphicsEnvironment somehow?
我可以用GraphicsEnvironment解决吗?
I would be greatful for any advice! 我将不胜感激任何建议!
If each screen can be seen by the OS as a seperate graphics device, you should be able to use something like... 如果操作系统可以将每个屏幕视为单独的图形设备,则应该可以使用...
import java.awt.EventQueue;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class TestGC {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
for (GraphicsDevice sd : sds) {
System.out.println(sd.getIDstring());
GraphicsConfiguration gc = sd.getDefaultConfiguration();
JFrame f = new JFrame(gc);
f.add(new JLabel(sd.getIDstring()));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
centerOn(f, gc);
f.setVisible(true);
}
}
});
}
private static void centerOn(JFrame f, GraphicsConfiguration gc) {
Rectangle bounds = gc.getBounds();
int x = bounds.x + ((bounds.width - f.getWidth()) / 2);
int y = bounds.y + ((bounds.height - f.getHeight()) / 2);
f.setLocation(x, y);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.