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

前端 未结 3 1459
既然无缘
既然无缘 2020-12-16 19:13

I would like to customize my titlebar, minimize-, maximize- and the close-button. So I used setUndecorated(true); on my JFrame, but I still want to be able to r

相关标签:
3条回答
  • 2020-12-16 19:54

    I found a nice method in RootPane that gave me this functionality, so now I only have to find out how to customize the titlebar and the buttons on it.

    I added this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); in my constructor for UndecoratedFrame.

    There is some more reading about this on Sexy Swing App – The Unified Toolbar and How to control window decorations

    0 讨论(0)
  • 2020-12-16 19:58

    As you said, you have a border on your root pane. As a consequence, there is at least one location (below the palce where your border is drawn) where your root pane is the upmost component. As a consequence, you can add it a mouse listener and a mouse motion listener.

    When your root pane is clicked (and the mouse button is pressed), your mouse and motion listeners will inform you of the initial and actual mouse position. As a consequence, you can update your frame size of the offset between both values, making your frame resizable.

    0 讨论(0)
  • 2020-12-16 19:58

    Resizing Components shows one way.

    0 讨论(0)
提交回复
热议问题