Java 图形用户界面之javax.swing包(二) JButton、JLabel、JTextArea、JTextField

Class JButton

继承的接口有ImageObserver , ItemSelectable , MenuContainer , Serializable , Accessible , SwingConstants六个

直接子类:BasicArrowButton , MetalComboBoxButton

继承的类 AbstractButton

方法

public JButton()

创建一个没有设置文本或图标的按钮

public JButton(Icon icon)

创建一个带有图标的按钮

public JButton(String text)

创建一个带文本的按钮

public JButton(Action a)

创建一个按钮,其中的属性取自提供的Action

public JButton(String text, Icon icon)

创建一个带有初始文本和图标的按钮


Class JLabel

实现的接口有ImageObserver , MenuContainer , Serializable , Accessible , SwingConstants五个

已知直接子类:BasicComboBoxRenderer , DefaultListCellRenderer , DefaultTableCellRenderer , DefaultTreeCellRenderer

继承了JComponent类

方法

JLabel()

创建一个没有图像的JLabel实例,标题为空字符串

JLabel(Icon image)

使用指定的图像创建一个 JLabel实例。

JLabel(Icon image, int horizontalAlignment)

创建一个具有指定图像和水平对齐的 JLabel实例。
JLabel(String text)
使用指定的文本创建一个 JLabel实例。
JLabel(String text, Icon icon, int horizontalAlignment)
创建具有 JLabel文本,图像和水平对齐的JLabel实例。
JLabel(String text, int horizontalAlignment)
创建一个具有指定文本和水平对齐的 JLabel实例。
 
public String getText()
返回标签显示的文本字符串
public void setText(String text)
定义该组件将显示的单行文本。如果文本的值为空,则不显示任何内容。
public Icon getIcon()
返回标签显示的图形图像
public void setIcon(Icon icon)
定义该组件将显示的图标。如果图标的值为空,则不显示任何内容。
public Component getLabelFor()
获取此标签的组件
 

Class JTextArea

实现的接口有ImageObserver , MenuContainer , Serializable , Accessible , Scrollable
继承JTextComponent
 

方法

public JTextArea()

构造一个新的TextAreea。设置默认模型,初始字符串为空,行/列设置为0.

public JTextArea(int rows, int columns)

构造具有指定行数和列数的新的空TextArea。

public JTextArea(String text)

构造一个新的TextArea,并显示指定的文本。

public JTextArea(String text, int rows, int columns)

构造具有指定文本和行数和列数的新TextArea。

public void append(String str)

将给定的文本附加到文档的末尾。 如果模型为空或字符串为空或为空,则不执行任何操作。

public void replaceRange(String str, int start, int end)

用指定的新文本替换指定的开始到结束位置的文本。 如果模型为空,则不做任何操作。 如果新的字符串为空或为空,只需删除。

public int getRows()

返回TextArea中的行数。

public void setRows(int rows)

设置此TextArea的行数。 在设置新值后调用invalidate()。

protected int getRowsHeight()

定义一行高度的含义。 这默认为字体的高度。

public int getColumns()

返回TextArea中的列数。

public void setColumns(int columns)

设置此TextArea的列数。 设置新值后,invalidate()。

protected int getColumnWidth

获取列宽。 什么是列的意思可以被认为是一些相当弱的概念的一些字体。 此方法用于定义列的宽度。 默认情况下,这被定义为使用的字体的字符m的宽度。 这种方法可以重新定义为一些替代量。

public Dimension getPreferredSize()

返回TextArea的首选大小。 这是显示文本所需大小的最大值和视口所请求的大小。

public void setFont(Font f)

设置当前字体。 这将删除缓存的行高和列宽,以便反映新字体,并调用revalidate()


 Class JTextField

实现的接口有ImageObserver , MenuContainer , Serializable , Accessible , Scrollable , SwingConstants

六个

已知直接子类:DefaultTreeCellEditor.DefaultTextField , JFormattedTextField , JPasswordField

继承的类JTextComponent

方法

public JTextField()

构建新的TextField 。 创建默认模型,初始字符串为null ,列数设置为0。

public JTextField(String text)

构造一个新TextField用指定文本初始化。 创建默认模型,列数为0。

public JTextField(int columns)

构造一个新的空的TextField与指定的列数。 创建默认模型,初始字符串设置为null

public JTextField(String text, int columns)

构造一个新的TextField ,用指定的文本和列进行初始化。 创建默认模型。

public JTextField(Document doc, String text, int columns)

构造一个新的JTextField ,它使用给定的文本存储模型和给定的列数。 这是其他构造函数通过其提供的构造函数。 如果文档是null ,则会创建默认模型。

猜你喜欢

转载自www.cnblogs.com/heibaimao123/p/9493357.html