Virupaksha
asked on
text is disappearing
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.getNa me(),label Font,g2D.g etFontRend erContext( ));
layout.draw(g2D,available. width/4,av ailable.he ight/2+(in t)origin.g etY());
updateUI();
Font labelFont = new Font("Helvetica",Font.BOLD
Graphics g = getGraphics();
setOpaque(true);
Graphics2D g2D = (Graphics2D) g;
TextLayout layout = new TextLayout(viewSpecs.getNa
layout.draw(g2D,available.
updateUI();
ASKER
actually the above code is not wriiten in the paint() method. i tried with and without updateUI(),repaint(), also setOpaque().
ASKER
actually the above code is not wriiten in the paint() method. i tried with and without updateUI(),repaint(), also setOpaque().
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.
Mayank.
ASKER
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.
Can you please post a part of your code so that it is a little clearer....
Mayank.
Mayank.
ASKER
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(TViewSpe cs viewSpecs, TData td, TEventBar tb, cyclesClass ca[]){
super( viewSpecs.getName() );
this.setName(viewSpecs.get Name());
this.viewSpecs = new TViewSpecs(viewSpecs);
traceData = td;
eventBar = tb;
cyclesArray = ca;
gradComp = new TGraduationHorzComponent(n ew 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.getAvai lable());
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.getNa me(),label Font,g2D.g etFontRend erContext( ));
layout.draw(g2D,available. width/4,av ailable.he ight/2+(in t)origin.g etY());
//updateUI();
//repaint();
}
}
public class TDrawBarGraphView extends TDrawView { TViewSpecs viewSpecs;
TGraduationHorzComponent gradComp;
TData traceData;
TEventBar eventBar;
cyclesClass cyclesArray[];
public TDrawBarGraphView(TViewSpe
super( viewSpecs.getName() );
this.setName(viewSpecs.get
this.viewSpecs = new TViewSpecs(viewSpecs);
traceData = td;
eventBar = tb;
cyclesArray = ca;
gradComp = new TGraduationHorzComponent(n
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.getAvai
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).
}
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
new TGraphComponentSpecs(specs
add(graphComp);
currXPos += width;
}
Font labelFont = new Font("Helvetica",Font.BOLD
Graphics g = getGraphics();
//setOpaque(true);
Graphics2D g2D = (Graphics2D) g;
TextLayout layout = new TextLayout(viewSpecs.getNa
layout.draw(g2D,available.
//updateUI();
//repaint();
}
}
Ok, so is the problem occuring even after commenting the updateUI () part? Where is the setupGraphComp () method called?
Mayank.
Mayank.
ASKER
it is called in the same class (ie TDrawBarGraphView),sorry i forgot to tell you that i am not using applet
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.
Mayank.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
i solved that problem by creating some component which draws the text, then i added that component to the above class, it worked.
Good :-)
ASKER
hi objects i want to ask you one question, you mentioned about paintComponent() method but that is protected, how to call or implement that.
Just override it the same way you override paint()
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.
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.
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
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
Mayank.