|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
Easy Learn Java: Programming Articles, Examples and Tips - Page 376
Previous
1060 Stories (530 Pages, 2 Per Page)
Next
Text
|
If you work with text, you need to know about the following user interface text
components.
| Component |
Lines |
Style |
Use |
JLabel |
1 plain or HTML "page" and/or an icon |
plain or HTML |
For displaying a fixed line of text. Can be HTML |
JTextField |
1 |
plain |
For entering or displaying one line of plain text. |
JFormattedTextField |
1 |
plain |
Added in SDK 1.4, JFormattedTextField is a subclass of
JTextField for which the type of entry may be specified. For
example, a field can be constructed to only accept integer values. |
JPasswordField |
1 |
plain |
For entering one line of plain text that displays a symbol
instead of the characters, ie, for entering passwords. Subclass of
JTextField. |
JTextArea |
many |
plain |
For entering or displaying multiple lines of plain text. Put it
into a JScrollPane to add scrolling. |
Advanced text components
For display of formatted documents, you might use JEditorPane (for
displaying plain, HTML, or RTF text) or JTextPane, which extends
JEditorPane to allow embedded images and components.
Additional Text features
- Font.
- Text graphics (The Graphics drawString method).
- Summary - Strings.
- Newline Characters.
comments? | | Score: 0
|
Posted by jalex on Wednesday, June 22, 2005 (00:00:00) (2057 reads)
|
Where to declare components
|
Components are typically declared in one of several places:
Field variables
Some components should be declared as field variables (instance variables,
member variables). This is the appropriate place to declare components which
must be referenced after the interface is constructed. Typically these are
text fields or text areas, check boxes, etc. Those components whose values must
be gotten or set.
Local variables
Local variables should be used for components which are never referenced after
the interface is constructed. Typically these are panels for holding components,
buttons (whose interaction is thru their listeners), ... Local variables
disappear when the method they are in returns, but the component will continue
to exist if it has been added to the interface.
Anonymous
Anonymous creation is typical with labels, which can be created and added in one
step and never assigned to a variable. Of course, if the appearance (font,
alignment, ...) must be changed, then they should be put in a local variable.
Some programs use labels for output (not a good idea), and in this case they
should be field variables. Example
content.add(new JLabel("Look at this"));
comments? | | Score: 0
|
Posted by jalex on Tuesday, June 21, 2005 (00:00:00) (2039 reads)
|
|
|