简体   繁体   English

如何制作自定义窗口而无边框仍可调整大小

[英]How can I make a custom Window without borders that is still resizable

Hi to all programmers out there! 大家好,大家好! :D :D

I want to create a JFrame without borders and size buttons. 我想创建一个没有边框和大小按钮的JFrame For example like the frame of the Steam-program for PC. 例如,类似于PC的Steam程序的框架。 I searched and found JWindow and the setUndecorated method for JFrame . 我搜索并找到JWindowJFramesetUndecorated方法。

When I use one of these options I get a window without borders, but I can't resize it. 使用这些选项之一时,我会得到一个无边框的窗口,但无法调整其大小。 Is there an easy way to keep this feature, especially the "snap-feature"? 有没有简单的方法来保持此功能,尤其是“快照功能”? I mean Valve managed to solve this problem somehow :) 我的意思是Valve设法以某种方式解决了这个问题:)

This question describes perfectly what I want, but there is only one answer and it's not very helpful... 这个问题完美地描述了我想要的东西,但是只有一个答案,并且不是很有帮助...

Check out Resizing Components . 检查调整组件大小 It is a general purpose class that allows you to resize any component. 这是一个通用类,允许您调整任何组件的大小。 It will provide the appropriate cursor as the mouse is around the edge of the frame. 当鼠标位于框架边缘时,它将提供适当的光标。

Basic usage for a frame would be: 框架的基本用法是:

JFrame frame = new JFrame("SSCCE");
frame.setUndecorated( true );

ComponentResizer cr = new ComponentResizer();
cr.registerComponent(frame);

Of course you will need to make sure that the frame has blank border around the edges so the MouseEvents are passed to the frame and not the component added to the frame. 当然,您需要确保框架的边缘周围有空白边框,以便将MouseEvents传递到框架,而不是将组件添加到框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM