The following program has a JButton and a JLabel in a JFrame. I am using Flow Layout.
How do I get the JLabel to show directly below the JButton before clicking the JButton and after clicking the JButton?

Thank you!

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

public class checks extends JFrame
   private JButton button;
   private JLabel label;
   public checks()
       button = new JButton("Click Here");
       label = new JLabel ("I am here");
       Container container = getContentPane();
       container.setLayout (new FlowLayout());

       button.addActionListener (
         new ActionListener()
             public void actionPerformed( ActionEvent e)
                    label.setText("Who are you");
       setSize(500, 500);
    public static void main(String args[])
            checks m = new checks();

Recommended Answers

Use a different layout such as BorderLayout, BoxLayout, or GridLayout.
Lesson: Laying Out Components Within a Container

Jump to Post

All 2 Replies

Hello Ezzaral,

Thank you!


Be a part of the DaniWeb community

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