java怎么在边框中加单选按钮?
展开全部
import java.awt.EventQueue;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class Test {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test window = new Test();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Test() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
//****************************
//创建radioBtn
JRadioButton rdbtnNewRadioButton = new JRadioButton("aaa");
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("bbbb");
//设置btn位置
rdbtnNewRadioButton.setBounds(6, 126, 141, 23);
rdbtnNewRadioButton_1.setBounds(123, 126, 141, 23);
frame.getContentPane().add(rdbtnNewRadioButton);
frame.getContentPane().add(rdbtnNewRadioButton_1);
//分组radioBtn
ButtonGroup bg=new ButtonGroup();
bg.add(rdbtnNewRadioButton_1);
bg.add(rdbtnNewRadioButton);
}
}
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class Test {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test window = new Test();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Test() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
//****************************
//创建radioBtn
JRadioButton rdbtnNewRadioButton = new JRadioButton("aaa");
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("bbbb");
//设置btn位置
rdbtnNewRadioButton.setBounds(6, 126, 141, 23);
rdbtnNewRadioButton_1.setBounds(123, 126, 141, 23);
frame.getContentPane().add(rdbtnNewRadioButton);
frame.getContentPane().add(rdbtnNewRadioButton_1);
//分组radioBtn
ButtonGroup bg=new ButtonGroup();
bg.add(rdbtnNewRadioButton_1);
bg.add(rdbtnNewRadioButton);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JButton b=new JButton("botton");
JPanel jpb=new JPanel();
jpb.setLayout(new GridLayout(3,3));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add( b);
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.setBorder(new LineBorder(Color.red,2));
JPanel jpb=new JPanel();
jpb.setLayout(new GridLayout(3,3));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add( b);
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.add(new JLabel(""));
jpb.setBorder(new LineBorder(Color.red,2));
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Border不是容器,不能添加
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询