我有一个在 MacBook 上开发的全屏 JFrame,效果很好。背景能够改变颜色和东西。现在我把它移到我的 Windows 盒子里,背景是白色的,当我告诉它时它似乎不想改变。为什么会这样?
这是设置我的窗口的代码(简而言之):
JFrame frame;
DisplayMode dm;
frame = new JFrame();
frame.setBackground(new Color(0.3F, 0.3F, 0.3F));
dm = new DisplayMode(Main.width, Main.height, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
screen = new ScreenManager();
screen.setFullScreen(dm, frame);
这是设置 JFrames 全屏的代码。
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import javax.swing.JFrame;
public class ScreenManager
{
public static GraphicsDevice vc;
public ScreenManager()
{
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
vc = env.getDefaultScreenDevice();
}
public void setFullScreen(DisplayMode dm, JFrame window)
{
window.setUndecorated(true);
window.setResizable(false);
vc.setFullScreenWindow(window);
if (dm != null && vc.isDisplayChangeSupported())
{
try
{
vc.setDisplayMode(dm);
}
catch (IllegalArgumentException e)
{
//No need to do anything.
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}