将单选按钮设置为背景

时间:2013-07-13 09:54:39

标签: java swing layout jlabel jradiobutton

我试图将单选按钮设置为背景,以便用户选择。

这是代码..

public class FirstWindow extends JFrame {

    private JTextField search;
    private JRadioButton author,title,both;
    private ButtonGroup grp;

    public FirstWindow() {
       super("My App");
       setLayout(new BorderLayout());

    JLabel backGround = new JLabel(new ImageIcon("C:\\Users\\Kareem Abdo\\Desktop\\3.Jpg"));
    backGround.setLayout(null);
    add(backGround);

    search = new JTextField("Search...");
    search.setFont(new Font("Arial",Font.PLAIN,16));
    search.setSize(150, 30);
    search.setLocation(20, 20);
    backGround.add(search);

    author = new JRadioButton("Author",true);
    author.setLocation(20, 25);
    backGround.add(author);

    title = new JRadioButton("Title",false);
    title.setLocation(25, 25);
    backGround.add(title);

    both = new JRadioButton("Both",false);
    both.setLocation(250, 250);
    backGround.add(both);

    grp = new ButtonGroup();
    grp.add(author);
    grp.add(title);
    grp.add(both);

但是单选按钮没有出现在屏幕上!

1 个答案:

答案 0 :(得分:3)