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

こ雲淡風輕ζ 提交于 2019-12-11 07:29:52

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/4670225/removing-a-frames-title-bar-keeping-the-resize-mechanims-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!