java - 如何为没有标题栏的 JFrame 提供拖动功能?

标签 java swing jframe drag

我正在创建一个在其 titleBar 中有四个按钮的 JFrame。

JFrame frame=new JFrame("custom JFrame with 4 buttons in title");
frame.setUndecorated(true);

JPanel button_panel=new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton button_1=new JButton("+");
JButton button_2=new JButton("↑");
JButton button_3=new JButton("-");
JButton button_4=new JButton("system tray");

button_panel.add(button_1);
button_panel.add(button_2);
button_panel.add(button_3);
button_panel.add(button_4);

frame.getContentPane().add(button_panel,BorderLayout.NORTH);

现在,我有一个标题栏中有四个按钮的 JFrame。

但是,如何为这个自定义 JFrame 提供拖动功能?

最佳答案

is it the only solution?

嗯,我知道的唯一解决方案是使用 MouseListeners。

有关更通用的解决方案,您可以查看 Moving Windows它允许您使任何 Swing 组件可拖动。

关于java - 如何为没有标题栏的 JFrame 提供拖动功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5505627/

相关文章:

java - 设置Jframe不总是在最上面

java - CMake - 安装后设置文件权限(java)

java - 如何检查 Swing 中的文本是否被选中?

java - 通过另一个 JOptionPane 打开 JOptionPane

java - 将 .swf 文件嵌入到我的 Jframe 中

java - 将背景图片添加到 JFrame

java - Azure 脱机同步来自 1 :n relationship in Android mobile app 的数据

java - 如何删除 Eclipse 浏览工具栏?

Javafx双向绑定(bind)SimpleDoubleProperty SimpleStringProperty数组越界

java - 重新定义 JRadioButton 中 Tab 键的行为?