Total members 11894 |It is currently Sun Nov 24, 2024 5:02 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 startend;
  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(nullfalsefalse));
  }
  public 
void paintComponent(Graphics g) {
  
Graphics2D graphics2D = (Graphics2Dg;
    
Dimension size getSize();
    
float width = (float) size.width;
  
float  X0;
    
lineBreakMeasurer.setPosition(start);
    while (
lineBreakMeasurer.getPosition() < end) {
    
TextLayout textLayout lineBreakMeasurer.nextLayout(width);
    
+= textLayout.getAscent();
    
0;
    
textLayout.draw(graphics2DXY);
  
+= 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(200200));
    
frame.show();
  }





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

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : java Break Line for text
 the text file i saved all in one line. How can i solve it?     -  
 Line Styles in java     -  
 Reading a File Line by Line in php     -  
 Java- Copy text area into disabled text area     -  
 Break in Nested Loops     -  
 Text Texture in java     -  
 Text to speech in java     -  
 change Font of text in java     -  
 draw text effects in java     -  
 uploading text file to java program     -  



Topic Tags

Java Graphics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com