2016-03-06 136 views
1

我有一個桌面LibGDX項目和我的主要(DesktopLauncher)類擴展JFrame(它將是undecorated和不可調整大小)。我將作爲組件添加到容器中的LwjglCanvas中的LibGDX OpenGL畫布渲染出來。現在,這是一個奇怪的問題:有時我可以在畫布周圍看到3-4-5px的邊框,可以進行一些可疑的調整大小。LwjglCanvas與JFrame調整大小

Not cool resizing

這裏是我的類:

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是真實可見。我試圖移動畫布(定義的setLocation()線),我看到它周圍有一個邊界: Border around canvas

而作爲一個未經修飾的窗口: Border around canvas-undecorated

我已經嘗試了很多事情,但毫無效果:

  • 我改變了佈局類型
  • 我創建了一個新JPanel,增加畫布到它,並設置爲setContentPane()
  • 試圖setPreferedSize,setMaximumSize,了setMinimumSize
  • 搜索... setBorder()或..setResizable()方法,但沒有成功

我怎樣才能擺脫在畫布周圍這種可怕的邊界?

+0

去除JFrame的延伸,只是把這個代碼發佈System.setProperty(「org.lwjgl前.opengl.Window.undecorated「,」true「); – Hllink

回答

2

你DesktopLauncher應該是這樣的:

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); 
    } 
} 

所以現在你有一個bordeless,unresizeable遊戲窗口。

對於你的情況,如果你仍然想與擺動使用它,只是爲了這個:

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); 
} 
+0

酷,但它不會做這項工作 - 這將禁用Java Swing,並且我需要它(我需要使用一些swing功能).... –

+0

它仍然適用於您的情況,只需創建配置並將它設置在this.canvas = new LwjglCanvas(new Main(DesktopLauncher.inst),config);並在設置System.setProperty(「org.lwjgl.opengl.Window.undecorated」,「true」)之前;它應該像魅力一樣工作。 – Hllink

+0

我的不好。 config.resizable = false;做了這份工作。謝謝你! :) –