How to put a JButton at a specific location?

后端 未结 3 758
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 06:12

I know that there are already very similar questions to my question on stackoverflow, but neither one of them answers my question. I want to put my JButton on a specific locatio

3条回答
  •  既然无缘
    2021-01-27 06:46

    If you want to put the item into a specific coordinate you have to use null Layout:

    Example:

    public void newClass(){
    
      public newClass(){
    
        JPanel panel = new JPanel();
        JButton button = new JButton("button1");
    
    
       panel.setLayout(null);
       button.setBounds(x,y,X,Y);
       panel.add(button);
    }
    
    public static void main(String[] args){
          newClass();
     }
    
    }
    

    Doing Without a Layout Manager (Absolute Positioning)

提交回复
热议问题