0

I want to set the full screen to a java.awt.Window, but it doesn't work on 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!

nbro
  • 15,395
  • 32
  • 113
  • 196
xirururu
  • 5,028
  • 9
  • 35
  • 64

2 Answers2

1

You can also do it using the class Toolkit (on 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

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. See this post for more information: Java Fullscreen mode not working on Ubuntu

Community
  • 1
  • 1
nbro
  • 15,395
  • 32
  • 113
  • 196
0

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

       }

    }
Revive
  • 2,248
  • 1
  • 16
  • 23