Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Setting Multi-Line label on the Button 
 

This section shows you how to set the multi line label on the button in Java Swing Applications.

 

Setting Multi-Line label on the Button

                         

This section shows you how to set the multi line label on the button in Java Swing Applications.

This program uses html class from javax.swing.text.html*; package and then breaks the text label of the button into two lines. If you run the program it will look like following image:

Multiline Labe of the Button

HTML:
This is the class from the javax.swing.text.html.*; package of Java. This class provides the facility to use the html tags in java application for texts. There are <html></html> tag and <br> tag have been used in this program. Tags of html are used with the string which is the label of the button.

Here is the code of the program:

import javax.swing.*;
import javax.swing.text.html.*;
import java.awt.*;

public class MultilineLabelButton{
  public static void main(String[] args){
    JFrame frame = new JFrame("Multiline Label for Button");
    String lbl = "<html>" "This label" "<br>" "is in two lines" "</html>";
    Panel panel = new Panel();
    JButton button = new JButton(lbl);
    panel.add(button);
//    frame.add(button);
    frame.add(panel, BorderLayout.NORTH);
    frame.setSize(300200);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c com class orm ant form model io components sed color format component value byte int rgb show pixel for

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

4 comments so far (
post your own) View All Comments Latest 10 Comments:

this was very helpful also i keep using ur website for all my programming needs

Posted by Anil on Wednesday, 12.10.08 @ 18:07pm | #82613

sample program of swing gui in java

Posted by joergia on Thursday, 09.18.08 @ 09:55am | #80246

the setMnemonic() does not seem to have effect on a label set tis way in a JButton. PLease help.

Posted by Janani on Tuesday, 02.26.08 @ 16:39pm | #50136

i prefer this tutorial always,i get more idea on programming ,excellent,to understand the requirement of the ,n well built programmes with output,if possible please provide me the tutorials on "struts",right from basic
thanks

Posted by abhishek das on Saturday, 11.10.07 @ 16:22pm | #36849

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.