java – How to remove borders from a JFrame?

Question:

I would like to strip the borders of a JFrame . I used setUndecorated(true) , but it takes it out completely and I'd like to leave just the JFrame titlebar.

Answer:

Window borders are provided by the operating system (provided the window is marked as decorated). The window decoration includes the title bar, so you can't have one without having the other.

There is a way to do it: you can set your window to unadorned and implement a titlebar by hand. The problem is that you would have to make the maximize, minimize and close buttons yourself, worrying about their correct placement (on Mac OS and Ubuntu it's different from Window). Not to mention that I would have to make this bar respond to drag and drop by hand. In other words, it's not worth it (but the Chrome folks did!)

Scroll to Top