Java-GNOME 2.10 GNOME Tutorial | ||
---|---|---|
<<< Previous | The Widgets | Next >>> |
The Label widget displays a small amount of text. As the name implies, most labels are used to label another widget such as a Button, a MenuItem, or a OptionMenu.
Labels may contain mnemonics. Mnemonics are underlined characters in the label, used for keyboard navigation. Mnemonics are created by providing a string with an underscore before the mnemonic character, such as "_File", to the constructor or setText method, with the hasMnemonic parameter true.
Mnemonics automatically activate any activatable widget the label is inside, such as a Button; if the label is not inside the mnemonic's target widget, you have to tell the label about the target using setMnemonicWidget.
To make it easy to format text in a Label (changing colors, fonts, etc.), label text can be provided in a simple markup format. Here's how to create a label with a small font:
Markup strings are just a convenient way to set the PangoAttrList on a Label; setAttributes may be a simpler way to set attributes in some cases. Be careful though; PangoAttrList tends to cause internationalization problems, unless you're applying attributes to the entire string . The reason is that specifying the startIndex and endIndex for a PangoAttribute requires knowledge of the exact string being displayed, so translations will cause problems.
Labels can be made selectable with setSelectable. Selectable labels allow the user to copy the label contents to the clipboard. Only labels that contain useful-to-copy information - such as error messages - should be made selectable.
A label can contain any number of paragraphs, but will have performance problems if it contains more than a small number. Paragraphs are separated by newlines or other paragraph separators understood by Pango. Labels can automatically wrap text if you call setLineWrap. setJustify sets how the lines in a label align with one another. If you want to set how the label as a whole aligns in its available space, see Misc.setAlignment.
<<< Previous | Home | Next >>> |
CheckButton | Up | ComboBox |