How do you to create a JFrame with simple text?

java, jframe, jpanel, swing, text

Solution

Instead of creating the `JPanel`, try:

JLabel label = new JLabel("this is my text");
frame.add(label);
frame.pack();

Problem

I just want to make a JFrame that will say "Hello world", nothing big, no interaction needed. How do I do this? I can create the JFrame, however I do not know how to put a JPanel with simple text in it. Here is what I got so far ``` JFrame frame = new JFrame("Relief Valve"); frame.setResizable(false); frame.setLocation(500,300); JPanel p1 = new JPanel(); frame.setVisible(true); ```

Original source