0

I have a JPanel which works allright. But there's a problem. I add a component which draws background for whole JFrame and also adds some buttons.

Problem starts when the JPanel "packs"(pack()) itself and only half of the background is visible.

I've tried to set panel's size and preferred size but it didn't work.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
grizeldi
  • 180
  • 2
  • 12
  • 1
    Post your [SSCCE](http://www.sscce.org/) demonstrating the problem. – camickr Mar 05 '14 at 18:24
  • Use a BorderLayout on the JFrame and add the JPanel to the CENTER area of the layout. Add whatever you want to the JPanel. – Kevin Workman Mar 05 '14 at 18:25
  • can you please post the code? – rogue-one Mar 05 '14 at 18:25
  • 1
    [Don't use `setPreferredSize()` when you really mean to override `getPreferredSize()`](http://stackoverflow.com/q/7229226/230513). – trashgod Mar 05 '14 at 18:32
  • I've already changed the code so i can't post original one. But my changes still didn't fix it. P.S. My JFrame uses cardLayout. – grizeldi Mar 05 '14 at 18:33
  • 1
    I think it may have something to do with the `CardLayout`. The layout will size itself according the _largest_ component in the layout. So if there's a layout that is bigger than the preferred size of the background panel, it will stretch the background panel. If the image is hard coded with size values that are less than the stretched size, that's one thing that could cause it. Maybe use `getWidth()` and `getHeight()` for the `width` and `height` of `drawImage` and see what happens. This is all just a guess without seeing your code. Or a runnable example. – Paul Samsotha Mar 05 '14 at 18:39

0 Answers0