• Post Reply Bookmark Topic Watch Topic
  • New Topic

string contains a TAB will not be recognized in drawString(String str,int x, int y) method

 
Thilina Jayasundara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to draw a string into a graphic. This string contains a TAB such as "this is my string with \t and so on\n". But it seems the TAB will not be recognized.

How can I overcome that?
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you would need to use the Utilities.drawTabbedText(...) method.

I"ve never used it before so I would search the web for examples that use this method.
 
Thilina Jayasundara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used this method for do the print job.

public void printRecord (String rec,JFrame JFMainParent) {

StringReader SRReader = new StringReader (rec);
LineNumberReader LNRReader = new LineNumberReader (SRReader);
Font typeface = new Font ("Courier New", Font.PLAIN,10);
PrintJob PJPrint = Toolkit.getDefaultToolkit().getPrintJob (JFMainParent, "", new Properties());

if (PJPrint != null) {
Graphics GGraph = PJPrint.getGraphics ();
if (GGraph!= null) {
FontMetrics FMFont = GGraph.getFontMetrics (typeface);
int PAGE_HEIGHT = PJPrint.getPageDimension().height - 75;
int FONT_HEIGHT = FMFont.getHeight();
int FONT_DESCENT = FMFont.getDescent();
int CURRENT_HEIGHT = 75;
String NEXT_LINE;
GGraph.setFont (typeface);

try {
do {
NEXT_LINE = LNRReader.readLine ();
if (NEXT_LINE != null) {
if ((CURRENT_HEIGHT + FONT_HEIGHT) > PAGE_HEIGHT) {
GGraph.dispose();
GGraph = PJPrint.getGraphics ();
CURRENT_HEIGHT = 75;
}
CURRENT_HEIGHT += FONT_HEIGHT;
if (GGraph != null) {
GGraph.setFont (typeface);
GGraph.drawString (NEXT_LINE, 75, CURRENT_HEIGHT - FONT_DESCENT);
}
}
}
while (NEXT_LINE != null);
}
catch (EOFException EOF_EXCEPTION) { }
catch (Throwable TROW_ERR) { }
}
GGraph.finalize();
GGraph.dispose();
}
if (PJPrint != null)
PJPrint.end ();
}

So my problem occored in red color method. So what am i do for get right string(with tab spaces) through above code.please tell me how/where am i want to change above code?
 
Thilina Jayasundara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi expert/AnyOne,

Please help this problem as soon as possible. Now I’m facing big trouble for this matter. So Any one read my code and give me a solution Please
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) There is no need to shout. That is there is no need to use large bold text.

2) You've been given a suggestion. I don't see anywhere in your code where you have attempted to implement the suggestion

Search the forum for help. You know what method to use. Don't expect us to write the code for you.
 
Thilina Jayasundara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh really sorry about this. once again sorry and give me pardon.

Thanks for everyone for any kind of help. thanks god bless you.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:1) There is no need to shout. That is there is no need to use large bold text. . . .
I have changed that text to normal size.
 
Thilina Jayasundara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok , Thanks for everyone
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!