我买了并设置了第二台显示器。 当我打开eclipse并将其拖到第二台显示器上时,如果我运行swing应用程序,它们会出现在第一台显示器上。
其他信息:
我的司机和日食是最新的。
显示器1:笔记本电脑集成显示器,QHD,17'。一切都在扩展,包括挥杆。由集成的英特尔图形处理>>(Windows决定,这不能更改)
显示器2:外置HP 22'FHD显示器。当51%的窗口移动到此屏幕时,它会缩小(但仍然从原始大小上升,通常为1080p)。 NVIDIA Gpu处理>>(Windows决定,这不能更改)
实施例
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class test {
public static void main(String[] args){
new test();
}
public test(){
JFrame testingBlack = new JFrame("MCVe");
JPantest testingB = new JPantest();
testingBlack.add(testingB);
testingBlack.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testingBlack.setVisible(true);
}
private class JPantest extends JPanel{
public JPantest(){
super();
repaint();
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.drawLine(0, 0, 100, 100);
}
}
}
这个程序描绘了一条简单的线。我从ecplise运行它,它从第一台显示器打开,它很好。我拖动第二台显示器,它变黑了。
答案 0 :(得分:3)
是否有摆动参数使程序在第二台显示器上运行,或者至少在运行eclipse的显示器上运行?
IDE的位置无关紧要。任何无父窗口都将在屏幕的(0, 0)
坐标处初始化,该坐标等同于GraphicsEnvironment#getDefaultScreenDevice()
返回的坐标。您可以使用setLocationByPlatform
来允许窗口系统(OS)确定位置。如果要强制第二台显示器的位置,可以执行以下操作:
public Main() {
JFrame testingBlack = new JFrame("MCVe");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
GraphicsConfiguration gc = gds[1].getDefaultConfiguration();
Rectangle rect = gc.getBounds();
testingBlack.setLocation(rect.getLocation());
// or, if you like this style better
testingBlack.setLocation(GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getScreenDevices()[1]
.getDefaultConfiguration()
.getBounds()
.getLocation());
testingBlack.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testingBlack.setVisible(true);
}
确保您访问GraphicsDevice[]
中的正确设备以避免AIOOB例外。 [0]
处的那个应该是默认设备(虽然我认为没有这样的保证)。
如果我将摆动程序从第一台显示器移动到第二台显示器,它会变黑。那是为什么?
不知道。必须与您的显示器设置有关。