0

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!!

Edited by sciprog1: n/a

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by sciprog1
0

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);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.