简体   繁体   English

在Ubuntu上将全屏设置为java.awt.Window

[英]Setting the full screen to a java.awt.Window on Ubuntu

I want to set the full screen to a java.awt.Window, but it doesn't work on Ubuntu. 我想将全屏设置为java.awt.Window,但在Ubuntu上不起作用。

The following code doesn't work: 以下代码不起作用:

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

I think, the problem is in the line: 我认为问题在于:

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

If I change it to: 如果我将其更改为:

  wnd.setSize(400,300)

it will work. 它会工作。

Can someone help me? 有人能帮我吗? Thanks very much! 非常感谢!

You can also do it using the class Toolkit (on Win7): 您也可以使用类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);
   }
}

For more information about the class Toolkit, see this link to the documentation: http://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html 有关类Toolkit的更多信息,请参见以下文档链接: http : //docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html

If you are using Ubuntu or other linux versions, you could have some problems setting the full screen to your window or frame with the "normal" ways to do it. 如果您使用的是Ubuntu或其他Linux版本,则可能会遇到一些“常规”方式将全屏设置为窗口或框架的问题。 See this post for more information: Java Fullscreen mode not working on Ubuntu 有关更多信息,请参见此帖子: Java全屏模式在Ubuntu上不起作用

By using wnd.setLocation(100, 100) you are placing the Full Screen size image at an 100pixel x and y offset from the top left corner of the screen. 通过使用wnd.setLocation(100, 100)您将全屏尺寸图像放置在距屏幕wnd.setLocation(100, 100)像素x和y偏移处。 Remove this and it will work 删除它,它将起作用

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

       }

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.awt.Window的全屏问题 - Full screen issue with java.awt.Window 如何重绘java.awt.Window? - How to repaint a java.awt.Window? Java“ java.awt.Window”数组在位置0添加项目 - Java “java.awt.Window” Array add Item at position 0 如何在java.awt.Window屏幕上侦听变化? 使用setFullScreenWindow()时是否有办法将焦点放在其他Windows /程序上? - How to listen for a change in java.awt.Window screen? Is there a way to give focus to other windows/programs whilst using setFullScreenWindow()? 在Swing应用程序启动期间,首次调用JFrame构造函数需要很长时间(因为java.awt.Window()) - First call to JFrame constructor takes a long time during Swing application startup (because of java.awt.Window()) 你为什么要处理一个超出范围的java.awt.Window? - Why should you have to dispose() a java.awt.Window that goes out of scope? Java(Awt)中的全屏窗口事件在哪里? - Where is the full-screen window event in Java (Awt)? 调整窗口大小时Java AWT小程序白屏 - Java AWT applet white screen when resizing window Java AWT窗口未显示 - Java AWT Window not shown 除了使用 java.awt 机器人 class 之外,如何在 Selenium/Java 中退出全屏(Chrome)? - How to exit full screen (Chrome) in Selenium/Java other than using java.awt Robot class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM