?? text.html
字號:
</div> </div> </div> </div> </div> </div> <div class=PrintHeaders> <b>Trail:</b> Creating a GUI with JFC/Swing <br><b>Lesson:</b> Using Swing Components </div> <div id=LeftBar class=LeftBar_shown> <div id=Contents> <div class="linkLESSON"><a href="index.html">Using Swing Components</a></div><div class="linkAHEAD"><a href="components.html">A Visual Index to the Swing Components</a></div><div class="linkAHEAD"><a href="html.html">Using HTML in Swing Components</a></div><div class="linkAHEAD"><a href="toplevel.html">Using Top-Level Containers</a></div><div class="linkAHEAD"><a href="model.html">Using Models</a></div><div class="linkAHEAD"><a href="jcomponent.html">The JComponent Class</a></div><div class="nolinkAHEAD">Using Text Components</div><div class="linkBHEAD"><a href="generaltext.html">Text Component Features</a></div><div class="linkBHEAD"><a href="textapi.html">The Text Component API</a></div><div class="linkAHEAD"><a href="componentlist.html">How to Use Various Components</a></div><div class="linkBHEAD"><a href="applet.html">How to Make Applets</a></div><div class="linkBHEAD"><a href="button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a></div><div class="linkBHEAD"><a href="colorchooser.html">How to Use Color Choosers</a></div><div class="linkBHEAD"><a href="combobox.html">How to Use Combo Boxes</a></div><div class="linkBHEAD"><a href="dialog.html">How to Make Dialogs</a></div><div class="linkBHEAD"><a href="editorpane.html">How to Use Editor Panes and Text Panes</a></div><div class="linkBHEAD"><a href="filechooser.html">How to Use File Choosers</a></div><div class="linkBHEAD"><a href="formattedtextfield.html">How to Use Formatted Text Fields</a></div><div class="linkBHEAD"><a href="frame.html">How to Make Frames (Main Windows)</a></div><div class="linkBHEAD"><a href="internalframe.html">How to Use Internal Frames</a></div><div class="linkBHEAD"><a href="label.html">How to Use Labels</a></div><div class="linkBHEAD"><a href="layeredpane.html">How to Use Layered Panes</a></div><div class="linkBHEAD"><a href="list.html">How to Use Lists</a></div><div class="linkBHEAD"><a href="menu.html">How to Use Menus</a></div><div class="linkBHEAD"><a href="panel.html">How to Use Panels</a></div><div class="linkBHEAD"><a href="passwordfield.html">How to Use Password Fields</a></div><div class="linkBHEAD"><a href="progress.html">How to Use Progress Bars</a></div><div class="linkBHEAD"><a href="rootpane.html">How to Use Root Panes</a></div><div class="linkBHEAD"><a href="scrollpane.html">How to Use Scroll Panes</a></div><div class="linkBHEAD"><a href="separator.html">How to Use Separators</a></div><div class="linkBHEAD"><a href="slider.html">How to Use Sliders</a></div><div class="linkBHEAD"><a href="spinner.html">How to Use Spinners</a></div><div class="linkBHEAD"><a href="splitpane.html">How to Use Split Panes</a></div><div class="linkBHEAD"><a href="tabbedpane.html">How to Use Tabbed Panes</a></div><div class="linkBHEAD"><a href="table.html">How to Use Tables</a></div><div class="linkBHEAD"><a href="textarea.html">How to Use Text Areas</a></div><div class="linkBHEAD"><a href="textfield.html">How to Use Text Fields</a></div><div class="linkBHEAD"><a href="toolbar.html">How to Use Tool Bars</a></div><div class="linkBHEAD"><a href="tooltip.html">How to Use Tool Tips</a></div><div class="linkBHEAD"><a href="tree.html">How to Use Trees</a></div><div class="linkAHEAD"><a href="icon.html">How to Use Icons</a></div><div class="linkAHEAD"><a href="border.html">How to Use Borders</a></div><div class="linkAHEAD"><a href="problems.html">Solving Common Component Problems</a></div></div> </div> <div id=MainFlow class=MainFlow_indented> <span id=BreadCrumbs> <a href=../../index.html target=_top>Home Page</a> > <a href=../index.html target=_top>Creating a GUI with JFC/Swing</a> > <a href=index.html target=_top>Using Swing Components</a> </span> <div class=NavBit> <a target=_top href=jcomponent.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=generaltext.html>Next »</a> </div> <div id=PageTitle>Using Text Components</div> <blockquote>This section gives you background informationyou might need when usingSwing's text components.If you intend to use an unstyled text component —a <a href="textfield.html">text field</a>,<a href="passwordfield.html">password field</a>,<a href="formattedtextfield.html">formatted text field</a>, or<a href="textarea.html">text area</a>—we recommend that you go to its how-to pageand return here only if necessary.If you intend to use a styled text component,then you're welcome to go to<a href="editorpane.html">How to Use Editor Panes and Text Panes</a>,but you'll probably need to read this section as well.If you don't know which component you need,read on.<p>Swing's text components display text andoptionally allow the user to edit the text.Programs need text components for tasksranging from the straightforward(enter a word and press Enter)to the complex(display and edit styled text withembedded images in an Asian language).<p>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 of Swing's text components inherit fromthe same superclass,<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/JTextComponent.html"><code>JTextComponent</code></a>, which provides a highly-configurableand powerful foundation for text manipulation.<p>The following figure shows the <code>JTextComponent</code> hierarchy.<p><center><IMG SRC="../../figures/uiswing/components/10jtextcomp.gif" WIDTH="495" HEIGHT="161" ALIGN="BOTTOM" ALT="Swing's hierarchy of text components"></center></p><br><font color=red>[PENDING:Please update this figure to add JFormattedTextField,which is a subclass of JTextField.]</font><p>The following picture shows an application called TextSamplerDemo that usesone of each of Swing's text components. <p><center><IMG SRC="../../figures/uiswing/components/TextSamplerDemoMetal.png" WIDTH="531" HEIGHT="406" ALIGN="BOTTOM" ALT="An application that provides a sample of each Swing text component"></center></p><blockquote><hr><strong>Try this:</strong> <ol><li> <a href="http://java.sun.com/docs/books/tutorialJWS/uiswing/components/examples/TextSamplerDemo.jnlp">Run TextSamplerDemo</a> (it requires release 6) using<a class="TutorialLink" target="_top" href="../../information/javawebstart.html">Java<sup><font size=-2>TM</font></sup> Web Start</a>. Or, to compile and run the example yourself, consult the <a href="examples/index.html#TextSamplerDemo">example index</a>.<li> Type some text into the text field and press Enter. Do the same with the password field. The label beneath the fields is updated when you press Enter.<li> Try entering valid and invalid dates into the formatted text field. Note that when you press Enter the label beneath is updated only if the date is valid. <li> Select and edit text in the text area and the text pane. Use special keyboard keys to cut, copy, and paste text.<li> Try to edit the text in the editor pane, which has been made uneditable with a call to <code>setEditable</code>.<li> Look in the text pane to find an example of an embedded component and an embedded icon.</ol><hr></blockquote><p>TextSamplerDemo uses the text componentsin very basic ways.The following table tells you a bit more aboutwhat you can do with eachkind of text component.<p><table cellpadding=5 border=1><tr><th> Group</th><th> Description</th><th> Swing Classes</th></tr><tr><th> Text Controls</th><td>Also known simply as text fields,text controlscan display and edit only one line of text.Like buttons, they generate action events.Use them to get a small amountof textual information from the userand take some action after the text entry is complete.</td><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTextField.html"><code>JTextField</code></a> and its subclasses <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JPasswordField.html"><code>JPasswordField</code></a> and<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html"><code>JFormattedTextField</code></a></td></tr><tr><th> Plain Text Areas</th><td><code>JTextArea</code>can display and edit multiple lines of 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 enterunformatted text of any lengthor to display unformatted help information.</td><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTextArea.html"><code>JTextArea</code></a></td></tr><tr><th> Styled Text Areas</th><td>A styled text componentcan display and edit text using more than one font.Some styled text components allow embedded imagesand even embedded components.Styled text components are powerful and multi-facetedcomponents suitable for high-end needs,and offer more avenues for customization thanthe other text components.<p>Because they are so powerful and flexible,styled text components typically requiremore up-front programming to set up and use.One exception is thateditor panes can be easily loaded withformatted text from a URL, which makes them usefulfor displaying uneditable help information.</td><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JEditorPane.html"><code>JEditorPane</code></a><br> and its subclass<br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTextPane.html"><code>JTextPane</code></a></td></tr></table><p>In this Tutorial, we give you informationabout the foundation laid by <code>JTextComponent</code>and tell you how to accomplishsome common text-related tasks.Because <code>JTextComponent</code> and its subclasseshave too many featuresto be completely described in this Tutorial,please visit the<a href="http://forums.java.net/jive/forum.jspa?forumID=74&start=0">Swingand AWT forum</a> at <a href="http://java.net/">java.net</a>for help and information. </blockquote> <div class=NavBit> <a target=_top href=jcomponent.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=generaltext.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> The JComponent Class <br><b>Next page:</b> Text Component Features </div> </body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -