java - 如何在 JFrame 标题栏上放置一个按钮
问题描述
我想在 JFrame 标题栏上放置一个按钮,如下图所示。
当我使用 button.setBounds() 设置按钮的边界时,按钮隐藏在标题栏下方,如下所示。
我在下面给出了我尝试过的代码。
public class SetBoundsTest {
public static void main(String arg[]) {
JFrame frame = new JFrame("Test Frame");
frame.setSize(500, 250);
// Setting layout as null
frame.setLayout(null);
// Creating Button
JButton button = new JButton("Test");
// Setting position and size of a button
button.setBounds(150,-20,120,40);
button.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));
button.setBackground(Color.MAGENTA);
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
任何帮助是极大的赞赏。
解决方案
您可以像这样将框架设置为未装饰
frame.setUndecorated(true);
注意:在前面加上这个语句frame.setVisiblle(true);
推荐阅读
- node.js - QuerySnapshot.docChanges 已从属性更改为方法
- java - 通过 REST 连接到 SharePoint 2016 - 空响应?
- python - 沿特定轴添加/相乘张量和矢量
- javascript - 数据数组将行值列表塞进一个对象中
- django - 在任何页面加载时显示 django-bootstrap 模式
- angular - 组件库中的 Angular Font Awesome - FontAwesome:找不到 iconName=times 和 prefix=fas 的图标
- ios - 如何使用 Swift 4 在 iOS 应用程序中访问 GIT 提交?
- xamarin - Xamarin 和蓝牙...不是!低功耗蓝牙
- mysql - ReferenceError & d3plus 未定义
- sql - Mysql 从所有表中选择两列