Home Java Example Java Swing Setting Multi-Line label on the Button

Related Tutorials


 
 

Share on Google+Share on Google+

Setting Multi-Line label on the Button

Advertisement
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.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Related Tutorials

Discuss: Setting Multi-Line label on the Button   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
bacbim
April 12, 2012
learn swing

thank you so much.
DMCA.com