Using Text Components
来源:互联网 发布:战舰世界塞班数据 编辑:程序博客网 时间:2024/05/17 05:11
Using Text Components
This section provides background information you might need when using Swing text components. If you intend to use an unstyled text component — atext field, password field, formatted text field, or text area — go to its how-to page and return here only if necessary. If you intend to use a styled text component, seeHow to Use Editor Panes and Text Panes, and read this section as well. If you do not know which component you need, read on.
Swing text components display text and optionally allow the user to edit the text. Programs need text components for tasks ranging from the straightforward (enter a word and press Enter) to the complex (display and edit styled text with embedded images in an Asian language).
Swing provides six text components, along with supporting classes and interfaces that meet even the most complex text requirements. In spite of their different uses and capabilities, all Swing text components inherit from the same superclass,JTextComponent
, which provides a highly-configurable and powerful foundation for text manipulation.
The following figure shows the JTextComponent
hierarchy.
The following picture shows an application called TextSamplerDemo
that uses each Swing text component.
Try this:
- Click the Launch button to run TextSamplerDemo using Java™ Web Start (download JDK 7 or later). Alternatively, to compile and run the example yourself, consult theexample index.
- Type some text in the text field and press Enter. Do the same in the password field. The label beneath the fields is updated when you press Enter.
- Try entering valid and invalid dates into the formatted text field. Note that when you press Enter the label beneath the fields is updated only if the date is valid.
- Select and edit text in the text area and the text pane. Use keyboard bindings, Ctrl-X, Ctrl-C, and Ctrl-V, to cut, copy, and paste text, respectively.
- Try to edit the text in the editor pane, which has been made uneditable with a call to
setEditable
. - Look in the text pane to find an example of an embedded component and an embedded icon.
The TextSamplerDemo
example uses the text components in very basic ways. The following table tells you more about what you can do with each kind of text component.
JTextField
and its subclassesJPasswordField
and JFormattedTextField
JTextArea
can display multiple lines of editable text. Although a text area can display text in any font, all of the text is in the same font. Use a text area to allow the user to enter unformatted text of any length or to display unformatted help information.JTextArea
Because they are so powerful and flexible, styled text components typically require more initial programming to set up and use. One exception is that editor panes can be easily loaded with formatted text from a URL, which makes them useful for displaying uneditable help information.
JEditorPane
and its subclass
JTextPane
This Tutorial provides information about the foundation laid by the JTextComponent
class and tells you how to accomplish some common text-related tasks. Because theJTextComponent
class and its subclasses have too many features to be completely described in this Tutorial, please visit theSwing & AWT forum at java.net for help and information.
Learn more about text components in JavaFX, see the Using Text and Text Effects in JavaFX and Using JavaFX UI Controls: Text Field tutorials.
- Using Text Components
- Using components
- Using Swing Components(1)
- Using ColdFusion components--properly
- react-bits:Using Pure Components
- Day3-9.Using other components
- Developing COM Components using VC-ATL(1)
- Developing COM Components using VC-ATL(2)
- Developing COM Components using VC-ATL(3)
- Developing COM Components using VC-ATL(1)
- Building components by using code behind
- Developing COM Components using VC-ATL
- Using Graphics Filters to Extend Basic Components
- Unity3D说明文档翻译-Using Components
- Full Text Indexing using Oracle Text
- text edit control using function
- Developing COM Components using VC-ATL(1-2)
- Developing COM Components using VC-ATL(2-2)
- hd1874畅通工程续
- CCArmature类层次图结构
- 2014-08-12
- 鼠标屏幕取词技术的原理和实现
- 讨论程序员一天代码量
- Using Text Components
- 彩票投注软件开发必须考虑的因数
- 菜鸟的安卓实习之路----dialog大小,位置等的调整
- C++求最大公约数和最小公倍数
- Twitter实时URL抓取服务架构 - SpiderDuck与NoSQL
- 可能改变你一生的英语名言警句
- ALV EDIT_MASK应用-负号前置/小数位处理 .
- 最短路(Dijkstra)
- linux下实现g++编译链接c++源文件和头文件