import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; public class TestBonds extends JFrame { public TestBonds() { setTitle("TestBonds"); setLayout(null); //这是重点 setSize(500,500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); JPanel p1 = new JPanel(); p1.setBounds(30, 30, 200, 200); p1.setBorder(BorderFactory.createTitledBorder("p1")); add(p1); JButton bt = new JButton("屩"); bt.setFont(new Font(null,Font.PLAIN,50)); bt.setBackground(Color.RED); //bt.setBorderPainted(false); bt.setBounds(300, 300, 100, 100); add(bt); setVisible(true); } /** * @param args */ public static void main(String[] args) { new TestBonds(); } }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)