Evan Troxell
Evan Troxell

Reputation: 1

Resizing or removing Java JFrame headers

I am creating a java application with a set size (it is a project creation screen for now, and I don't want this screen to be large). I'm trying to set the JFrame I use to display in such a way that I have even spacing between all elements and the top/bottom of the frame, but I don't know the size of the frame header (or what the strip at the top of the frame is called, I don't know what else to call it). Does anyone know what the height of the header is? Is there a way to resize or remove it outright? I'd like to have more control over what I can do with the frame. Thanks

The header I would like to know about:

https://i.sstatic.net/A6adI.png

Upvotes: 0

Views: 38

Answers (1)

Michael
Michael

Reputation: 721

To remove the title bar, set frame.setUndecorated(true);. This will remove all decorations for the JFrame.

Full example:

package test;

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

public class Example {

    public Example() {
        JFrame frame = new JFrame("Some title");
        frame.add(new JLabel("test"), BorderLayout.CENTER);

        frame.setUndecorated(true);
        frame.pack();
        frame.setSize(500, 200);
        frame.setVisible(true);
    }

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Example ex = new Example();
            }
        });
    }

}

Upvotes: 0

Related Questions