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
位置
,但没有指定JRadioButton
的大小。您也需要指定,但由于您采取的方法完全错误,因此我不会在后面说一句话:-)请查看此相关内容我已将背景布局设置为null,以便能够按照我的要求对组件进行排序,我不希望布局管理器对其进行排序“我不希望布局管理器对其进行排序”然后期待所有类型的问题,目前正在看到的,停止打扰我们。如果您具有布局组件的智能,则可以将该逻辑放入自定义布局管理器中(提示:此问题表明您没有)。