title: Java Jpanel setBounds not working
body: <p>I encountered a wierd problem in a JFrame cointaining 2 JPanels.
  I got a class called "SlotCheck" which extends JFrame.
  and i got a Class called "Slot" which Extends JPanel.
  In the SlotCheck constructor i add 2 Slot instances called sl and s2.
  I use setBounds() to put them in two diffrent locations on the board.</p>
  
  <p>sl.setBounds works and puts it where i indicate.
  but s2.setBounds doesnt work and it puts it in (0,0).</p>
  
  <p>here is how it looks: </p>
  
  <p><img src="https://i.stack.imgur.com/bHiNx.png" alt="enter image description here"></p>
  
  <p>i would love to know why it does that.</p>
  
  <p>here is the SlotCheck class:</p>
  
  <pre><code>package Try1;
  import java.io.IOException;
  import javax.swing.JFrame;
  
  public class SlotCheck extends JFrame{
    private Slot sl;
    private Slot s2;
    public SlotCheck() throws IOException{
    sl = new Slot(4,2,SlotType.white);
    System.out.print(sl.toString());
    add(sl);
    sl.setBounds(100,0,40,300);
    sl.setVisible(true);
  
    s2 = new Slot(6,2,SlotType.black);
    System.out.print(s2.toString());
    add(s2);
    s2.setBounds(200,0,40,300);
    s2.setVisible(true);
    }
  
    public static void main(String[]args) throws IOException{
    SlotCheck sc = new SlotCheck();
    sc.setDefaultCloseOperation(EXIT_ON_CLOSE);
    sc.setTitle("check of slot");
    sc.setVisible(true);
    sc.setLocation(300, 200);
    sc.setSize(400,400);
    }
  }
  </code></pre>
  
  <p>And here is the Slot class:</p>
  
  <p>It is kind of long but i hope you will understand. 
  Also the paintComponent class is down in the code and i think its the one that matters so u can go there.</p>
  
  <pre><code>  package Try1;
  
  import java.awt.Graphics;
  import java.awt.Image;
  import java.io.File;
  import java.io.IOException;
  import java.util.Stack;
  
  import javax.imageio.ImageIO;
  import javax.swing.JPanel;
  
  // slot is a defined place on the backgammon board that can hold 
  // one type of pieces black or white.
  //there are 24 slots 12 on each side and 6 in each quartor.
  //if a slot holds 2 or more pieces those pieces cannot be eaten.
  public class Slot extends JPanel{
    private int slotNumber;
    private int piecesAmount;
    private SlotType type;
    private Stack&lt;WhitePiece&gt; wPieces;
    private Stack&lt;BlackPiece&gt; bPieces;
    private Image wPieceImage;
    private Image bPieceImage;
    public Slot() throws IOException{
    type = SlotType.empty;
    piecesAmount = 0;
    setSize(300,40);
    wPieces = new Stack&lt;WhitePiece&gt;();
    bPieces = new Stack&lt;BlackPiece&gt;();
    wPieceImage = ImageIO.read(new File("pics/whitePiece.png"));
    bPieceImage = ImageIO.read(new File("pics/blackPiece.png"));
   }
    public Slot(int pA, int sN, SlotType t) throws IOException{
    if(t != SlotType.empty){
        piecesAmount = pA;
        slotNumber = sN;
        type = t;
        wPieces = new Stack&lt;WhitePiece&gt;();
        bPieces = new Stack&lt;BlackPiece&gt;();
        wPieceImage = ImageIO.read(new File("pics/whitePiece.png"));
        bPieceImage = ImageIO.read(new File("pics/blackPiece.png"));
        if(t == SlotType.black){
            for(int i=0;i&lt;pA;i++)
                bPieces.push(new BlackPiece());
        }else{
            for(int i=0;i&lt;pA;i++)
                wPieces.push(new WhitePiece());
        }
    }
    }
    public SlotType getType(){
    return type;
    }
    public void setType(SlotType t){
    if(piecesAmount == 0)
      type = t;
    }
     public int getPiecesAmount(){
    return piecesAmount;
    }
     public void setPiecesAmount(int pa) throws IOException{ 
    if(type != SlotType.empty){
        piecesAmount = pa;
        if(type == SlotType.black){
           if(pa&gt;bPieces.size())
             for(int i=0;i&lt;(pa-bPieces.size());i++)
                bPieces.push(new BlackPiece());
           else
               if(pa&lt;bPieces.size())
                   for(int i=0;i&lt;(bPieces.size()-pa);i++)
                       bPieces.pop();
       }
        else{
            if(pa&gt;wPieces.size())
                 for(int i=0;i&lt;(pa-wPieces.size());i++)
                    wPieces.push(new WhitePiece());
               else
                   if(pa&lt;wPieces.size())
                       for(int i=0;i&lt;(wPieces.size()-pa);i++)
                           wPieces.pop();
        }
    }else{
        System.out.println("Slot #"+slotNumber+" is Empty Slot");
    }
    }
    public void decreasePiecesAmount(){
    if(type != SlotType.empty){
        piecesAmount --;
        if(type == SlotType.black)
            bPieces.pop();
        else
            wPieces.pop();
    }
    }
    public void increasePiecesAmount() throws IOException{
    if(type != SlotType.empty){
        piecesAmount ++;
        if(type == SlotType.black)
            bPieces.push(new BlackPiece());
        else
            wPieces.push(new WhitePiece());
    }
    }
    public void pushPiece(){
  
    }
    public void paintComponent(Graphics g){     
    if(type == SlotType.empty){ 
        System.out.println("no type selected slot is empty Slot  Number"+slotNumber);
    }else
        if(type == SlotType.white){
          if(!wPieces.isEmpty()){
          try {
              wPieces.push(new WhitePiece());
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          if(slotNumber &lt;= 11){
            for(int i=0;i&lt;piecesAmount;i++){
              g.drawImage( wPieceImage, 5, i*30, null);
            }
          }
          else{
              for(int i=0;i&lt;piecesAmount;i++){
                  g.drawImage(wPieceImage, 5,300-(i*30), null);
              }
         }
          }else{
              System.out.println("Slot Stack is Empty Slot #"+slotNumber);
          }
        }else
        {
            if(!bPieces.isEmpty()){
  
            if(slotNumber&lt;=11){
               for(int i=0;i&lt;piecesAmount;i++){
                  g.drawImage(bPieceImage, 5, i*30, 30, 30, null);
              }
            }else{
                for(int i=0;i&lt;piecesAmount;i++){
                      g.drawImage(bPieceImage, 5, 300-(i*30), 30, 30, null);
                }  
            }
      }
            else{
        System.out.println("Slot Stack is empty Slot #"+slotNumber);
     }
  }
  
  }
  protected void setSlotNumber(int sN){
    slotNumber = sN;
  }
  public int getSlotNumber(){
    return slotNumber;
  }
  public String toString(){
  return "Slot #"+slotNumber+"\nSlot Type is: "+type.toString()+"\nAmount of pieces is: "+piecesAmount;
    }
  
  }
  </code></pre>
  
  <p>I appritiate your help.</p>