Hello Members,

If possible, kindly let me know why I am not able to see the text in the buttons("Button" and "Button two!") when I run this Java program:

import java.awt.*;
import javax.swing.*;

public class Sample extends JFrame {

    private JButton b1, b2;
    private final Container container;
    
    public Sample()
    {
        b1 = new JButton ("Button");
        b2 = new JButton ("Button two!");
        
        container = getContentPane();
        container.setLayout(null);
        
        container.add(b1);
        container.add(b2);
        b1.setBounds(50, 50, 50, 50);
        b2.setBounds(50, 125, 50, 50);
        
        
        setSize(500, 500);
        setVisible(true);
    }
    
    public static void main (String args[])
    {
        Sample sample = new Sample();
    }
}

Thank you!!

Recommended Answers

All 2 Replies

The width of each button is given too small.
Try to replace lines 19 and 20 with the following width of 150:

b1.setBounds(50, 50, 150, 50);
b2.setBounds(50, 125, 150, 50);

Hello tong1,

Thank you!! It works now.

Regards,
sciprog1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.