0

*SOLVED:I made a Jframe with a specific background that I need. I found on Youtube that if I want to have a picture for background,you have to choose Null Layout.I did it,and when I run my program then the window remains small(not at normal size) at left corner on my screen. I need Null Layout because I use other labels up to Label,which I use as background.I have almost done with my project,and I have only this problem.Any idea? Thank you! **I found the solution. You can choose Absolute Layout and it has no problem !!!

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user2933161
  • 33
  • 1
  • 3
  • 12
  • Youtube is not the best place to learn this. – tbodt Nov 21 '13 at 00:21
  • 1
    *"if I want to have a picture for background,you have to choose Null Layout"* - Not true...You can use a `JLabel` as the main background or use a `JPanel`, overriding it's `paintComponent` method to render the image. Both these allow you to supply a layout manager and be set as the frame's content pane...Oh, I assume you're using `pack` on the frame as well – MadProgrammer Nov 21 '13 at 00:22
  • @MadProgrammer I think this constructor, [`JLabel(Icon image)`](http://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html#JLabel(javax.swing.Icon)) creates a label with only an image for you – vandale Nov 21 '13 at 00:30
  • @vandale That's my point. If you don't need to dynamically change the size of the image, you can simply use a `JLabel`. A `JLabel` is just a `JComponent`, hence you can apply a layout manager to and add components to it... – MadProgrammer Nov 21 '13 at 00:37
  • @MadProgrammer sorry, I misread,: I thought you meant to override the `paintComponent` on the `JLabel` also – vandale Nov 21 '13 at 00:41
  • @vandale No worries ;) – MadProgrammer Nov 21 '13 at 00:43
  • @MadProgrammer If i use a jlabel and then I add other components to it,then I can not see other components because they will be under the Jlabel,which I want for background. – user2933161 Nov 21 '13 at 00:46
  • @user2933161 If you add components to a container, they will be rendered above the container, for [example](http://stackoverflow.com/questions/12253979/place-jlabel-on-top-of-jlabel-with-image-in/12254063#12254063) – MadProgrammer Nov 21 '13 at 00:49
  • I found the solution. You can choose Absolute Layout and it has no problem !!! – user2933161 Nov 21 '13 at 00:54
  • If you have found the answer on your own, you should post an answer and mark it as accepted instead of editing it into your question. – Nick McCurdy Nov 21 '13 at 01:20
  • @user2933161, `You can choose Absolute Layout and it has no problem` - That is NOT the solution. You should NOT use a null layout. All you need to do is use a layout manager like you would do for any other panel that you want to add components to. – camickr Nov 21 '13 at 02:04

0 Answers0