Java中的JPanel的函数setBounds()的用法误解

       建立一个JPanel,1024*512后,把下面的CoraseButtonPanel和Joint1ButtonPanel添加进去,然后运行,发现Joint1ButtonPanel里的按钮不显示,调试发现setBounds的大小是相对于自己的Panel而言的,把Joint1ButtonPanel里的按钮的setBounds横坐标换成512以内的数就可以了。

 class CoraseButtonPanel extends JPanel{


     public CoraseButtonPanel(){




         this.setLayout(null);
         this.setBounds(0,0,512,512);
         this.setBorder( BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK,1),
         "Coarse Adjustment",TitledBorder.DEFAULT_POSITION,TitledBorder.TOP,new java.awt.Font("Times New Roman",0,20)));


        CoraseStartButton=new JButton("Start");
         CoraseStartButton.setSize(80,30);
        CoraseStartButton.setBounds(180,460,80,30);
        CorasePreceedButton = new JButton("Preceed");
        CorasePreceedButton.setSize(100,30);
        CorasePreceedButton.setBounds(280,460,100,30);
        CoraseCancleButton = new JButton("Cancle");
        CoraseCancleButton .setSize(80,30);
        CoraseCancleButton.setBounds(400,460,80,30);


        CorasePreceedButton.setEnabled(false);
        CoraseCancleButton.setEnabled(false);
         CoraseStartButton.addActionListener(new CoraseStartAction());
         CorasePreceedButton.addActionListener(new CorasepreceedAction());
         CoraseCancleButton.addActionListener(new CorasecancleAction());


       add(CoraseStartButton);
       add(CorasePreceedButton);
       add(CoraseCancleButton);

     }

   }


  class Joint1ButtonPanel extends JPanel{




    public Joint1ButtonPanel(){


          this.setLayout(null);
        this.setBounds(512,0,512,512);
       this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK,1),
      "Joint1 Adjustment",TitledBorder.DEFAULT_POSITION,TitledBorder.TOP,new java.awt.Font("Times New Roman",0,20)));

       Joint1BackButton=new JButton("Back");
       Joint1BackButton.setSize(80,30);
       Joint1BackButton.setBounds(700,460,80,30);


       Joint1PreceedButton = new JButton("Preceed");
       Joint1PreceedButton.setSize(100,30);
        Joint1PreceedButton.setBounds(800,460,100,30);


      Joint1CancleButton = new JButton("Cancle");
      Joint1CancleButton.setSize(80,30);
      Joint1CancleButton.setBounds(900,460,80,30);


      Joint1BackButton.setEnabled(false);
      Joint1PreceedButton.setEnabled(false);
      Joint1CancleButton .setEnabled(false);
     Joint1BackButton.addActionListener(new Joint1BackAction());
     Joint1PreceedButton.addActionListener(new Joint1PreceedAction());
     Joint1CancleButton.addActionListener(new Joint1CancleAction());


     add(Joint1BackButton);
          add(Joint1PreceedButton);
      add(Joint1CancleButton);
    }


  }

你可能感兴趣的:(Java中的JPanel的函数setBounds()的用法误解)