-1

I was trying to set Radio Button to a background in order to allow the user to select.

Here is the code ..

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);

But the radio buttons doesn't appear on the screen!

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them, along with layout padding & borders for white space. 3) Don't extend frame or other top level containers. Instead create & use an instance of one. – Andrew Thompson Jul 13 '13 at 09:59
  • You are specifying only `location`, but no size for `JRadioButton`. You need to specify that too, but since its a completely wrong approach you taking, I won't say a word after this :-) – nIcE cOw Jul 13 '13 at 10:17
  • Please have a look at this related [example (2nd code)](http://stackoverflow.com/a/11428289/1057230) – nIcE cOw Jul 13 '13 at 13:13

1 Answers1

3
Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • i had set the layout of backGround to null in order to be able to sort the components as I want, I don't want the layout manager to sort them – Kareem Abdo Jul 13 '13 at 10:18
  • 1
    *"I don't want the layout manager to sort them"* Then expect all the types of problems currently being seen, & stop bothering us. If you had the smarts to layout the components, you could put that logic in a custom layout manager (tip: this question indicates you don't). – Andrew Thompson Jul 13 '13 at 11:17