Java Swing JFrame doesn't work in Ubuntu
I wrote the following program in Java:
import javax.swing.*;
import java.awt.*;
public class Main { public static void main(String[] args) { JFrame frame = new JFrame("Test"); frame.setSize(new Dimension(800, 600)); frame.setVisible(true); }
}However when I run it the icon shows up in the bar on the left, but no actual window is displayed. I use the openjdk-8 at the moment, installed via apt-get install openjdk-8-jdk. I also tried this with Oracle Java and it didn't work either.
How can I get my code to display a Frame?
3 Answers
Java should work everywhere. Try to download a simple Java application from Internet too see if it works or not.
I think you need to set the position of your JFrame. Tryframe.setLocation(x, y);
This run successfully on my ubuntu 20 with jdk-11.
This answer on Stack Overflow by mapadj
fixed mine:
1If you set setResizable false before setting the bounds, you will not have the problem. as Gergely Szilagyi stated before, you are getting rid of the scrollbars, but the size of the window is locked and therefore you end up with 9 or 10 pixels of extra space in the frame. I just had the same problem. thanks for the help.
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"