Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:05 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: java Break Line for text
PostPosted: Tue Nov 11, 2008 8:22 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

java Break Line for text
Code:
import java.awt.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.font.*;
import java.util.Hashtable;

public class LineBreakExample extends JPanel {
  private LineBreakMeasurer lineBreakMeasurer;
private int start, end;
  private static Hashtable hash = new Hashtable();
 
  private static AttributedString attributedString = new AttributedString(
       "Java is an Object Oriented Programming Language which has "
      + " an extensive class library available in the core language packages.
    Java "+ "was designed with networking in mind and comes with many classes "
    +" to develop sophisticated Internet communications. ",
      hash);
  public LineBreakExample() {
    AttributedCharacterIterator attributedCharacterIterator =
          attributedString.getIterator();
    start = attributedCharacterIterator.getBeginIndex();
    end = attributedCharacterIterator.getEndIndex();
    lineBreakMeasurer = new LineBreakMeasurer(attributedCharacterIterator,
     new FontRenderContext(null, false, false));
  }
  public void paintComponent(Graphics g) {
  Graphics2D graphics2D = (Graphics2D) g;
    Dimension size = getSize();
    float width = (float) size.width;
  float  X, Y = 0;
    lineBreakMeasurer.setPosition(start);
    while (lineBreakMeasurer.getPosition() < end) {
    TextLayout textLayout = lineBreakMeasurer.nextLayout(width);
    Y += textLayout.getAscent();
    X = 0;
    textLayout.draw(graphics2D, X, Y);
  Y += textLayout.getDescent() + textLayout.getLeading();
    }
  }
  public static void main(String[] args) {
    JFrame frame = new JFrame("Show Line Break");
    LineBreakExample controller = new LineBreakExample();
    frame.getContentPane().add(controller,"Center");
    frame.setSize(new Dimension(200, 200));
    frame.show();
  }
}


Attachments:
File comment: line breaks in java
lineBreak.gif
lineBreak.gif [ 4.96 KiB | Viewed 5225 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Search records from text file
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team