Java 将单选按钮设置为背景

Java 将单选按钮设置为背景,java,swing,layout,jlabel,jradiobutton,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 Bo

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

这是密码

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);
但是单选按钮不会出现在屏幕上

  • JLabel(JLabel backGround=new JLabel
    )没有实现任何
    LayoutManager
    ,否则添加到
    JLabel
    的任何
    JComponent
    都不可见

  • 最好从(API中预先实现的
    FlowLayout
    开始)


1)要更快地获得更好的帮助,请发布一个。2) javagui可能必须在许多平台上工作,在不同的屏幕分辨率上&使用不同的plaf。因此,它们不利于部件的精确放置。要为健壮的GUI组织组件,请使用布局管理器或它们的组合,以及空白的布局填充和边框。3) 不要延伸框架或其他顶级容器。而是创建并使用一个实例。您只指定了
位置
,但没有指定
JRadioButton
的大小。您也需要指定,但由于您采取的方法完全错误,因此我不会在后面说一句话:-)请查看此相关内容我已将背景布局设置为null,以便能够按照我的要求对组件进行排序,我不希望布局管理器对其进行排序“我不希望布局管理器对其进行排序”然后期待所有类型的问题,目前正在看到的,停止打扰我们。如果您具有布局组件的智能,则可以将该逻辑放入自定义布局管理器中(提示:此问题表明您没有)。