What is JButton - Java Swing

Java examples for Swing:JButton

Introduction

JButton is a push button or a command button.

Constructors of the JButton Class

Constructor                                    Description
JButton()                                      Creates a JButton without any label or icon.
JButton(String text)                           Creates a JButton and sets the specified text as its label.
JButton(Icon icon)                             Creates a JButton with an icon and no label.
JButton(String text, Icon icon)                Creates a JButton with the specified label and icon.
JButton(Action action)                         Creates a JButton with an Action object.

create a JButton with its text as Close, like so:

import javax.swing.JButton;

public class Main {
  public static void main(String[] args) {
    JButton closeButton = new JButton("Close");
  }
}

Related Tutorials