Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

mixing scrollable text and graphics

  Asked By: Kerri    Date: Mar 02    Category: Java    Views: 826
  

I am a newbie to java. I have a problem regarding combining a
textarea with a scrollbar with some graphics like rectangles inserted
intermittently between the text in an applet. Basically I am reading
some data from a file. The volume of data is huge and so the textarea
in which I want to display this information should include a
scrollbar. Say the first line of the textarea contains the string "M
K T A Y I A K Q R Q I S". There are many such lines in the scrollable
textarea, each containing 13 such one-letter codes. Now, I have to
use two symbols - a rectangle and an arrow (say a rectangle + the >
sign) that should point from a certain one-letter code to another
one. Say the first rectangle symbol is from the 3rd character 'T' to
the 8th character 'K' (on the first line) and the first arrow symbol
is from the 15th character 'V' to the 19th character 'F' (on the
second line). So, the first four lines of my display should be like
this :

M K T A Y I A K Q R Q I S
|||||||||||
F V K S H F S R Q L E E R
||||||||>

I can put the above information "as is" in text format in a
scrollable textarea. But what I want to do is to use a scrollable
text area that should contain the text (lines 1,3,..) and graphics
(rectangles drawn using fillRect() on lines 2,4,..) alternately. I
have not yet mastered the use of all the classes and methods under
AWT/Swing and am at a loss to tackle this problem. The g.fillRect()
method called from paint(Graphics g) cannot display rectangles in the
textarea. Moreover, if I attempt to use g.drawString() for displaying
the text and g.fillRect() for displaying the rectangles, both are
shown in the applet, but I am unable to display information for all
the lines beyond the height of the applet, as I no longer have the
scrollbar facility of the textarea. I hope I did not make the whole
thing very complicated. I shall appreciate it very much if someone
helps me out with some code for combining text and graphics on
alternate lines with scrolling functionality for both text and
graphics together.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Guadalupe Rogers     Answered On: Mar 02

if u want to insert Text and graphics  both. it is convienent to you
that u have to use JTextPane class. JTextArea does not support every kind of
graphics but JTextpane support all type of graphics.

so i'll recomend you to use JTextPane class to solve your problem

 
Didn't find what you were looking for? Find more on mixing scrollable text and graphics Or get search suggestion and latest updates.




Tagged: