你好,怎么能够做到性别那个框的效果?
追答import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Test extends JFrame {
public Test() {
JPanel pane = new JPanel(null);
JPanel sexPane = new JPanel();
// 设置标题边框,其实就这一句在起作用
sexPane.setBorder(BorderFactory.createTitledBorder("性别"));
sexPane.add(new JRadioButton("男"));
sexPane.add(new JRadioButton("女"));
getContentPane().add(pane);
pane.add(sexPane);
sexPane.setBounds(20, 20, 150, 80);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 200);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}
边框内容要是竖着排列的。