java jtextfield 居中

您所在的位置:网站首页 java窗体居中显示 java jtextfield 居中

java jtextfield 居中

2024-06-30 07:09| 来源: 网络整理| 查看: 265

多谢!

|

给你一个小例子,刚写的,呵呵:)

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class JTextFieldTest extends JFrame

{

public JTextFieldTest()

{

super("设置JTextField的文字的位置");

JTextField text = new JTextField("这些文字将居中显示",10);

text.setHorizontalAlignment(JTextField.CENTER);

getContentPane().add(text,BorderLayout.NORTH);

setSize(300,400);

show();

}

public static void main(String args[])

{

JTextFieldTest p = new JTextFieldTest();

p.addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

}

}

|

JTextField

public void setHorizontalAlignment(int alignment)

Sets the horizontal alignment of the text. Valid keys are:

JTextField.LEFT

JTextField.CENTER

JTextField.RIGHT

JTextField.LEADING

JTextField.TRAILING

invalidate and repaint are called when the alignment is set, and a PropertyChange event ("horizontalAlignment") is fired.

Parameters:

alignment - the alignment

Throws:

IllegalArgumentException - if alignment is not a valid key



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3