当前位置:首页 > 编程技术 > 正文

jframe如何设置可移动

jframe如何设置可移动

在Java中,使用`JFrame`时,可以通过继承`JFrame`类并重写其`setTitle( `和`setExtendedState( `方法来设置窗口的可移动性。...

在Java中,使用`JFrame`时,可以通过继承`JFrame`类并重写其`setTitle()`和`setExtendedState()`方法来设置窗口的可移动性。以下是一个简单的例子:

```java

import javax.swing.JFrame;

public class DraggableFrame extends JFrame {

public DraggableFrame() {

// 设置窗口标题

setTitle("可移动窗口");

// 设置窗口大小

setSize(300, 200);

// 设置窗口可见

setVisible(true);

// 窗口可移动

setResizable(true);

// 设置窗口初始位置

setLocationRelativeTo(null);

最新文章