2010-03-28 79 views
5

我的怪異監視器的原始分辨率無法被Windows識別,因此我必須爲其設置自定義分辨率。問題在於java不能識別它,因爲它不在Win7的「已批准」列表中,所以全屏模式會「卡住」。 Netbeans從全屏精細出來,所以必須有解決方法。任何人都知道嗎?自定義監視器未被Java識別的分辨率

//編輯(3/29/2010):它看起來像NetBeans是僞造全屏,而不是實際進入全屏獨佔模式,所以這可能實際上不可解決。現在,我也在僞裝它。但似乎java應該認識到有效的 DisplayMode是有效的。

這個例子重現問題:


package resolutionexample; 

import java.awt.Dimension; 
import java.awt.DisplayMode; 
import java.awt.GraphicsDevice; 
import java.awt.GraphicsEnvironment; 
import javax.swing.JFrame; 
import javax.swing.SwingUtilities; 

public class Main { 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable(){ 
      public void run() { 
       GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
       GraphicsDevice gd = ge.getDefaultScreenDevice(); 

       DisplayMode currentDM = gd.getDisplayMode(); 

       boolean currentInAvailable = false; 

       System.out.println("Available resolutions:"); 
       for (DisplayMode availDM : gd.getDisplayModes()){ 
        //System.out.println(availDM.getWidth() + "x" + availDM.getHeight()); 
        if (availDM.equals(currentDM)){ 
         currentInAvailable = true; 
        } 
       } 

       System.out.println("Current resolution: " + currentDM.getWidth() + "x" + currentDM.getHeight()); 

       System.out.println("Current in available: " + currentInAvailable); 


       JFrame frame = new JFrame("Resolution Bug Example"); 
       frame.setVisible(true); 
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

       if (!gd.isFullScreenSupported()){System.exit(0);} 

       gd.setFullScreenWindow(frame); 

       gd.setFullScreenWindow(null); 
      } 
     }); 
    } 
} 

輸出運行1680×1050(顯示器的靠不住的原始分辨率):

如果

run: 
Available resolutions: 
Current resolution: 1680x1050 
Current in available: false 
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid display mode 
     at sun.awt.Win32GraphicsDevice.setDisplayMode(Win32GraphicsDevice.java:393) 
     at sun.awt.Win32GraphicsDevice.setFullScreenWindow(Win32GraphicsDevice.java:329) 
     at resolutionexample.Main$1.run(Main.java:43) 
     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) 
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) 
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) 
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) 
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) 
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) 
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) 
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 
BUILD SUCCESSFUL (total time: 2 seconds) 

輸出設置我的分辨率爲1024x768運行前:


run: 
Available resolutions: 
Current resolution: 1024x768 
Current in available: true 
BUILD SUCCESSFUL (total time: 2 seconds) 

回答

2

卡住了什麼意思?不是一個好的分辨率或沒有真正的全屏模式?對於一個大屏幕上,你可以嘗試

Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment(). 
       getMaximumWindowBounds(); 
JFrame frame = new JFrame(); 
frame.setPreferredSize(new Dimension(rect.width, rect.height)); 

對於全屏切換,你可以簡單地複製sources from netbeans' MainWindow :-)

+0

它進入真正的全屏模式,但它不會出來,它也不會響應alt-tab卡住。 現在,我的確在使用與您所描述的類似的假全屏。 :) – Angie 2010-03-29 17:40:36

1

如何添加分辨率到Windows 7?

我用PowerStrip(http://entechtaiwan.com/util/ps.shtm)做過一次,但那是用於XP的。

+0

我可能會爲我的個人電腦工作,但我不願意向我的最終用戶解釋這一點;) – Angie 2010-03-29 17:45:08

相關問題