Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't display button

I can’t display button and i don’t know why
Is there any way to fix it

I want it to appear at the top in the far left

import java.awt.event.*;
import java.awt.*;

import javax.swing.*;

public class test extends JFrame{

    JButton b1 = new JButton("b1");
    
    public test() {
        
        b1.setBounds(0, 0, 125,100);
        
        add(b1);
        
    }

    public static void main(String[] args) {
            
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLayout(null);
        f.setSize(925, 500);
        f.setVisible(true);

    }

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I have edited your code like below to make it display the button

import javax.swing.*;

public class test extends JFrame{

    static JFrame f = new JFrame(); 
    static JButton b1 = new JButton("b1");
    
    public test() {   
        b1.setBounds(0, 0, 125,100); 
        f.add(b1); 
    }

    public static void main(String[] args) {    
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLayout(null);
        f.setSize(925, 500);
        f.setVisible(true);
        new test();
    }

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading