0

i got this code :

JFrame frame = new JFrame("FilesComparator");

    frame.setVisible(true);

    frame.setSize(1000, 600);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height
                / 2 - frame.getSize().height / 2);
    JButton buttonStart;
    JButton buttonCancel;

    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();


    buttonStart = new JButton("Start");
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.PAGE_END;

    buttonStart.addActionListener(new ActionStart());
    pane.add(buttonStart, c);
    buttonCancel = new JButton("Cancel");
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weighty = 15.0;
    c.anchor = GridBagConstraints.PAGE_END;
    buttonCancel.addActionListener(new ActionCancel());
    pane.add(buttonCancel, c);
}}

All works good . But when i want to add an image background ( image.jpeg) its never work. I think it's because of this layout. So my question is , how to set a background image to my frame ?

Thx for help

LedZelkin
  • 586
  • 1
  • 10
  • 24
  • Hopefully this [answer](http://stackoverflow.com/a/11372350/1057230), be able to help you in this. One more [detailed answer](http://stackoverflow.com/a/9866659/1057230) for more information. Second [example](http://stackoverflow.com/a/11428289/1057230), on this link also helps in this direction :-) – nIcE cOw Oct 04 '13 at 16:12
  • 1
    @nIcEcOw Thx for this , it worked like a char :) If your comment was an answer I would have accepted this one . – LedZelkin Oct 07 '13 at 08:31
  • Glad, it helped you somewhat. I wish I could post that as an answer, but that would lead to redundancy on the forum, which is considered a bad practice :-) Though for the rest, You're MOST WELCOME and KEEP SMILING :-) – nIcE cOw Oct 07 '13 at 09:14

1 Answers1

3

But when i want to add an image background ( image.jpeg) its never work

I don't see any code where you attempt to add a background image.

See Background Panel for a couple of approaches you can use depending on your requirement.

camickr
  • 321,443
  • 19
  • 166
  • 288