我有一个桌面 LibGDX 项目,我的主 (DesktopLauncher) 类扩展了 JFrame(它将是未修饰且不可调整大小的)。我在 LwjglCanvas 中渲染 LibGDX OpenGL Canvas ,该 Canvas 作为组件添加到容器中。现在有一个奇怪的问题:有时我可以看到 Canvas 周围有 3-4-5 像素的边框,这使得某些可疑的大小调整成为可能。
这是我的类(class):
public DesktopLauncher() {
this.setUndecorated(true);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle("Evil Engine (v. Lambda)");
Container container = this.getContentPane();
this.canvas = new LwjglCanvas(new Main(DesktopLauncher.inst));
// this.canvas.getCanvas().setLocation(200, -200);
// height of the task bar
int taskBarSize = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration()).bottom;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.canvas.getCanvas().setSize(screenSize.width, screenSize.height - taskBarSize);
container.add(this.canvas.getCanvas(), BorderLayout.CENTER);
this.pack();
this.setVisible(true);
}
当 setUndecorated 为 true 时就会出现问题。我尝试移动 Canvas (setLocation() 行),发现它周围有一个边框:
我尝试了很多方法,但没有任何效果:
- 我更改了布局类型
- 我创建了一个新的 JPanel,将 Canvas 添加到其中并设置为 setContentPane()
- 尝试过 setPreferedSize、setMaximumSize、setMinimumSize
- 搜索 ...setBorder() 或 ..setResizable() 方法,但没有成功
我怎样才能摆脱 Canvas 周围这个可怕的边框?
最佳答案
你的桌面启动器应该是这样的:
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.height =1024;
config.width= 768;
config.resizable = false;
config.title= "My App Title";
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
new LwjglApplication(new Game(), config);
}
}
现在你有了一个无边界、不可调整大小的游戏窗口。
对于你的情况,如果你仍然想将它与 swing 一起使用,只需这样做:
public DesktopLauncher() {
this.setUndecorated(true);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle("Evil Engine (v. Lambda)");
Container container = this.getContentPane();
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.resizable = false;
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
this.canvas = new LwjglCanvas(new Main(DesktopLauncher.inst),config);
// this.canvas.getCanvas().setLocation(200, -200);
// height of the task bar
int taskBarSize = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration()).bottom;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.canvas.getCanvas().setSize(screenSize.width, screenSize.height - taskBarSize);
container.add(this.canvas.getCanvas(), BorderLayout.CENTER);
this.pack();
this.setVisible(true);
}
关于java - LwjglCanvas 与 JFrame 调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35831228/