supertreta
supertreta

Reputation: 359

Removing a Frame's title bar keeping the resize mechanims - Java

My problem is related with what Jonas asked on the next topics:

How to add support for resizing when using an undecorated JFrame?

How can I customize the title bar on JFrame?

I want to create a custom window without the native title bar. This can be done by calling:

setUndecorated(true);

However, this also removes the re-size mechanism. So now I am using the next code:

 public UndecoratedFrame() {
 this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
    menu.add(item);
    menuBar.add(menu);
    this.setJMenuBar(menuBar);
    this.setUndecorated(true);
    this.getRootPane().setBorder(border);
    this.setSize(400,340);
    this.setVisible(true);
}

This returns a window like this: http://www.roseindia.net/java/example/java/swing/CreateJList.shtml (Consider only the title bar and borders)

How can I remove the top title bar without removing the re-size decorator? Or should I customize the default title bar? How can I do this by a simple way?

The idea is to end with a frame only with its borders (and the re-size working..). Then, I can create a custom title bar with a JPanel and buttons triggering the close, minimization, etc. OS events.

Thanks in advance for your support.

Upvotes: 1

Views: 4861

Answers (1)

ddimitrov
ddimitrov

Reputation: 3343

You need to implement your own mouse listeners and interpret the mouse gestures, programmatically resizing the window.

Another option is to use JIDE Common Layer - it provides multiple implementations of its ResizableSupport interface, including ResizableFrame which does what you describe.

http://www.jidesoft.com/javadoc/com/jidesoft/swing/ResizableFrame.html

Upvotes: 2

Related Questions