Skip to Content

Create AWT Label With Text Alignment Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Create AWT Label With Text Alignment Example
  3.         This java example shows how to create a label and align label text using
  4.         AWT Label class.
  5. */
  6.  
  7. import java.applet.Applet;
  8. import java.awt.Label;
  9.  
  10. /*
  11. <applet code="CreateLableWithAlignment" width=100 height=200>
  12. </applet>
  13. */
  14.  
  15. public class CreateLableWithAlignment extends Applet{
  16.  
  17.         public void init(){
  18.                
  19.                 /*
  20.                  * To create a label with it's text alignment use
  21.                  * Label(String text, int alignment)
  22.                  * constructor of AWT Label class.
  23.                  *
  24.                  * The possible alignment values are
  25.                  * Label.LEFT, Label.RIGHT, and Label.CENTER
  26.                  */
  27.                
  28.                 Label label1 = new Label("Left Aligned Label", Label.LEFT);
  29.                
  30.                 Label label2 = new Label("Right Aligned Label", Label.RIGHT);
  31.                
  32.                 Label label3 = new Label("Center Aligned Label", Label.CENTER);
  33.                
  34.                 //add labels
  35.                 add(label1);
  36.                 add(label2);
  37.                 add(label3);
  38.                
  39.                 /*
  40.                  * To change alignment of label's text use
  41.                  * void setAlignment(int alignment)
  42.                  * method of AWT Label class.
  43.                  */
  44.                
  45.                 Label label4 = new Label("Set Center Alignment");
  46.                 add(label4);
  47.                 label4.setAlignment(Label.CENTER);
  48.                
  49.         }
  50. }

Example Output