JButton, AbstractButton class in javax.swing: Types of constructors, Methods

JButton class: JButton class is push button class for Swing in javax.swing. By using Swing buttons icons and strings can be added to a button. It is a sub class of AbstractButton class.

Types of constructors defined by JButton class:

Type-1: By using icon for a button.

JButton(Icon i)

Type-2: By using string for a button.

JButton(String s)

Type-3: By using string and icon for a button.

JButton(String s, Icon i)

AbstractButton class: It is an abstract super class for Swing buttons. It supports rollover icons, which is displayed when mouse is positioned over a particular component.

Methods defined by AbstractButton class:

setDisabledIcon( ) method: It is used to set an icon for a component when it is disabled.

Syntax:

void setDisabledIcon(Icon di)

setPressedIcon( ) method: It is used to set an icon for a component when it is pressed.

Syntax:

void setPressedIcon(Icon pi)

setSelectedIcon( ) method: It is used to set an icon for a component when it is selected.

Syntax:

void setSelectedIcon(Icon si)

setRolloverIcon( ) method: It is used to set an icon for a component when it is rolled over.

Syntax:

void setRolloverIcon(Icon ri)

getText( ) method: It is used to obtain the button text.

Syntax:

String getText( )

setText( ) method: It is used to set the button text.

Syntax:

void setText(String s)

Leave a Reply