?
Solved

text is disappearing

Posted on 2003-03-24
18
Medium Priority
?
190 Views
Last Modified: 2010-03-31
i have written the following code to draw some text in the graph, but the text is disappearing just after displaying.

Font labelFont     = new Font("Helvetica",Font.BOLD,12);
Graphics g = getGraphics();
setOpaque(true);
Graphics2D     g2D          = (Graphics2D) g;
TextLayout layout = new TextLayout(viewSpecs.getName(),labelFont,g2D.getFontRenderContext());
 layout.draw(g2D,available.width/4,available.height/2+(int)origin.getY());
     updateUI();
0
Comment
Question by:Virupaksha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
  • +2
18 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 8194114
The update () method is probably doing so.... I guess its clearing the text.

Mayank.
0
 

Author Comment

by:Virupaksha
ID: 8194146
actually the above code is not wriiten in the paint() method. i tried with and without updateUI(),repaint(), also setOpaque().
0
 

Author Comment

by:Virupaksha
ID: 8194147
actually the above code is not wriiten in the paint() method. i tried with and without updateUI(),repaint(), also setOpaque().
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 8194161
What is the code in your paint () method?? Also, is the above code in your init () method? (I'm assuming that you're using Applets. If not, then please correct me..)

Mayank.
0
 

Author Comment

by:Virupaksha
ID: 8194181
there is no paint method for this class, actually i am calling some class to draw bars in the graph, so that class is containg paint() method. i cannot draw the text there because it will be for one bar, but i want it for the whole graph, that's why i am calling getGraphics() after drawing bars.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8194207
Can you please post a part of your code so that it is a little clearer....

Mayank.
0
 

Author Comment

by:Virupaksha
ID: 8194294
i am sending the code for the class where i am using the above code.

public class TDrawBarGraphView extends TDrawView {    TViewSpecs               viewSpecs;
    TGraduationHorzComponent     gradComp;
     TData traceData;
     TEventBar eventBar;
     cyclesClass cyclesArray[];

    public TDrawBarGraphView(TViewSpecs viewSpecs, TData td, TEventBar tb, cyclesClass ca[]){
     super( viewSpecs.getName() );
     this.setName(viewSpecs.getName());
     this.viewSpecs = new TViewSpecs(viewSpecs);
     traceData = td;
     eventBar = tb;
     cyclesArray = ca;
     gradComp = new TGraduationHorzComponent(new TViewSpecs(viewSpecs), traceData, eventBar, cyclesArray, (TDrawView)this);
     setLayout(new TBarGraphLayout(this, gradComp));
     //add(gradComp);

    }

    public TViewSpecs getViewSpecs(){
     return(viewSpecs);
    }

/*This method creates the bar graph components based on the viewspecs information */
    public void setupGraphComp(){

     Point          origin          = new Point(gradComp.getOrigin());
     Dimension     available     = new Dimension(gradComp.getAvailable());
     double          currXPos     = origin.getX();
     double          horzGap          = available.width / viewSpecs.getCount();
     boolean          drawEnclRect     = true;
     double          maxYVal          = (double)viewSpecs.getMaxY();


     if( horzGap < 4 )
         drawEnclRect = false;

    TGraphComponentSpecs    spec        = viewSpecs.getCompSpecs(0);
     double w = spec.width;
    if(w != 0){
    viewSpecs.getCompSpecs(0).width = viewSpecs.getCompSpecs(1).width;
    }

     for(int i=0; i < viewSpecs.getCount(); i++){
         TGraphVertComponent     graphComp;
         TGraphComponentSpecs specs = viewSpecs.getCompSpecs(i);
         double width = (available.width * specs.width)/
          (viewSpecs.getMaxX() - viewSpecs.getMinX() + w);
         double height = available.height;

         specs.drawEnclRect = drawEnclRect;
         graphComp = new TGraphVertComponent(new Point((int)currXPos, 0),
                              new Dimension((int)specs.width, (int)height),
                              new TGraphComponentSpecs(specs), true, maxYVal, viewSpecs);
         add(graphComp);
         currXPos += width;
     }

     Font          labelFont     = new Font("Helvetica",Font.BOLD,12);
     Graphics g = getGraphics();
     //setOpaque(true);
     Graphics2D     g2D          = (Graphics2D) g;
     TextLayout layout = new TextLayout(viewSpecs.getName(),labelFont,g2D.getFontRenderContext());
     layout.draw(g2D,available.width/4,available.height/2+(int)origin.getY());
     //updateUI();
     //repaint();

    }


}
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8194353
Ok, so is the problem occuring even after commenting the updateUI () part? Where is the setupGraphComp () method called?

Mayank.
0
 

Author Comment

by:Virupaksha
ID: 8194435
it is called in the same class (ie TDrawBarGraphView),sorry i forgot to tell you that i am not using applet
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8194455
Ok, maybe in some other method which you haven't shown here. It is obviously a problm of refrehsing or reloading which is occuring due to some method invocation occuring after the text is displaying, which is again clearing it. You will have to go through the hard process of checking the flow of control and determining the sequence of all method-calls.

Mayank.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 8197997
All your painting should be done in the paintCOmponent() method, as it is the class that is responsible for painting the component when required.
You should not use the getGraphics() method to paint to your component.
0
 

Author Comment

by:Virupaksha
ID: 8201325
mayank and objects thanks for your comments.
i solved that problem by creating some component which draws the text, then i added that component to the above class, it worked.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8201356
Good :-)
0
 

Author Comment

by:Virupaksha
ID: 8217122
hi objects i want to ask you one question, you mentioned about paintComponent() method but that is protected, how to call or implement that.
0
 
LVL 92

Expert Comment

by:objects
ID: 8221209
Just override it the same way you override paint()
0
 

Expert Comment

by:CleanupPing
ID: 9058521
Virupaksha:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9731942
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept objects' comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question