JPanel radioButtonPanel = new JPanel();
append = new JRadioButton("append");
build = new JRadioButton("x.x.1");
build.setSelected(true); //sets this button as selected on startup
small = new JRadioButton("x.1.x");
huge = new JRadioButton("1.x.x");
// Create the button group to keep only one selected.
ButtonGroup btnGroup = new ButtonGroup();
btnGroup.add(append);
btnGroup.add(build);
btnGroup.add(small);
btnGroup.add(huge);
# 1 楼答案
然后将按钮添加到JPanel或类似的东西中
# 2 楼答案
请尝试使用ButtonGroup组件,并向ButtonGroup对象添加两个名为男性和女性的JRadioButton组件,然后使用setVisible(true)将其显示在JFrame中;方法
以下代码应该很有用:-