【问题标题】:Setting the full screen to a java.awt.Window on Ubuntu在 Ubuntu 上将全屏设置为 java.awt.Window
【发布时间】:2014-08-13 15:40:40
【问题描述】:

我想将全屏设置为 java.awt.Window,但它在 Ubuntu 上不起作用。

以下代码不起作用:

import java.awt.*;
import javax.swing.*;

public class test 
{
    public static void main(String[] args) 
    {
        Window wnd = new Window(new Frame());

        wnd.setLocation(100, 100);
        wnd.setSize(wnd.getToolkit().getScreenSize());
        wnd.setBackground(Color.red);
        wnd.setVisible(true);
    }
}

我认为,问题出在:

  wnd.setSize(wnd.getToolkit().getScreenSize());

如果我将其更改为:

  wnd.setSize(400,300)

它会起作用的。

有人可以帮助我吗?非常感谢!

【问题讨论】:

  • 定义“不起作用”。会发生什么?
  • 嗨,艾弗里,什么都没发生。但是现在,我从 usar 那里得到了答案,它只是在 ubuntu 上不起作用。

标签: java awt


【解决方案1】:

您也可以使用类 Toolkit(在 Win7 上):

//other imports
import java.awt.Toolkit;

public class test
{
    public static void main(String[] args) 
    {
        Window wnd = new Window(new Frame());

        //Of course this set the window 100 px to the right
        // and 100 to the bottom
        wnd.setLocation(100, 100);

        //You use the Toolkit class!!
        //Now your window has the same size of your screen!!
        wnd.setSize(Toolkit.getDefaultToolkit().getScreenSize());

        wnd.setBackground(Color.red);
        wnd.setVisible(true);
   }
}

有关类 Toolkit 的更多信息,请参阅此文档链接:http://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html

如果您使用的是 Ubuntu 或其他 linux 版本,则使用“正常”方式将全屏设置为窗口或框架可能会遇到一些问题。 有关更多信息,请参阅此帖子:Java Fullscreen mode not working on Ubuntu

【讨论】:

  • 谢谢你!这篇文章解释了我的问题!
【解决方案2】:

通过使用wnd.setLocation(100, 100),您将全屏大小的图像放置在距屏幕左上角 100 像素 x 和 y 偏移处。 删除它,它会工作

    public class test {

    public static void main(String[] args) {

        Window wnd = new Window(new Frame());
        //wnd.setLocation(100, 100);
        wnd.setSize(wnd.getToolkit().getScreenSize());
        wnd.setBackground(Color.red);
        wnd.setVisible(true);

       }

    }

【讨论】:

  • 我试过了,还是不行。我用的是 Ubuntu,可能是问题所在?
  • 是的。 Usars 的答案应该用于 Ubuntu。只需删除 setLocation 偏移量即可。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-06
  • 2014-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-13
相关资源
最近更新 更多