did u try repaint()???
vemul
Main Topics
Browse All Topicshie,
I have a JFrame, with 3 JPanels "added" to it. Now, on a repaint on the JFrame, the top and the bottom frames get repainted properly (they have some buttons, textfields etc.) but the third panel (actually, it is a class that extends JPanel) doesnt get repainted properly. In this class, I have paintComponent() method where I paint some lines/circles etc. All I see in that region in my frame is the backGround color. By debugging. I realize that the g.Draw() lines of code DO get executed. (Graphics2D g). My conjecture is that for some reason, the background color gets applied to the JPanel after the execution of the relevant code, thus overWriting any effect of the custom paintings, whatsoever.
I am in a bit of a hurry, so some quick help will really be appreciated. I think this is an easy question, but still I'll give 100 points for any help I get :)
Thanx,
--Ankur.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well, the super.paintComponent() part already happens, so the problem definitely lies somewhere else.
repaint() -- as in from where ?
yeah, the pen color is set to one diff. from the background. and no, the g.drawLine didnt work :(
am increasing the points, seems like the question is not so trivial :)
--Ankur.
hie randy,
Sorry, none of them worked :(
I think I'll give the general structure of the code, maybe it'll help you identify the problem better...
--------------------------
Draw objDraw = new Draw();
myFrame.getContentPane().a
.
.
.
.
in the file Draw.java
class Draw() extends JPanel...
{
public void paintComponent()
{
super.paintComponent();
Graphics2D g2 = (Graphics2D) g;
drawShapes(g2);
}
public void drawShapes(Graphics2D g2)
{
g2.setPaint(axis);
g2.setStroke(dashed);
g2.draw(new Line2D.Double(wt/2,0,wt/2,
g2.draw(new Line2D.Double(0,ht/2,wt,ht
}
}// end of class Draw
Thanx for the prompt replies anyway :)
--Ankur.
hie randy,
Sorry, none of them worked :(
I think I'll give the general structure of the code, maybe it'll help you identify the problem better...
--------------------------
Draw objDraw = new Draw();
myFrame.getContentPane().a
.
.
.
.
in the file Draw.java
class Draw() extends JPanel...
{
public void paintComponent()
{
super.paintComponent();
Graphics2D g2 = (Graphics2D) g;
drawShapes(g2);
}
public void drawShapes(Graphics2D g2)
{
g2.setPaint(axis);
g2.setStroke(dashed);
g2.draw(new Line2D.Double(wt/2,0,wt/2,
g2.draw(new Line2D.Double(0,ht/2,wt,ht
}
}// end of class Draw
Thanx for the prompt replies anyway :)
--Ankur.
hie randy,
Sorry, none of them worked :(
I think I'll give the general structure of the code, maybe it'll help you identify the problem better...
--------------------------
Draw objDraw = new Draw();
myFrame.getContentPane().a
.
.
.
.
in the file Draw.java
class Draw() extends JPanel...
{
public void paintComponent()
{
super.paintComponent();
Graphics2D g2 = (Graphics2D) g;
drawShapes(g2);
}
public void drawShapes(Graphics2D g2)
{
g2.setPaint(axis);
g2.setStroke(dashed);
g2.draw(new Line2D.Double(wt/2,0,wt/2,
g2.draw(new Line2D.Double(0,ht/2,wt,ht
}
}// end of class Draw
Thanx for the prompt replies anyway :)
--Ankur.
The code you've posted is not complete so it's hard to tell exactly what the problem is.
Try displaying the value of wt and ht, and a solid colour for testing to narrow down the cause of the problem:
public void drawShapes(Graphics2D g2)
{
System.out.println(wt+":"+
//g2.setPaint(axis);
//g2.setStroke(dashed);
g2.setColor(Color.red);
g2.draw(new Line2D.Double(wt/2,0,wt/2,
g2.draw(new Line2D.Double(0,ht/2,wt,ht
}
Business Accounts
Answer for Membership
by: randydPosted on 2002-10-22 at 11:40:42ID: 7357362
override the paintComponent method to call super.paintComponenet first, then do your own painting.. as follows:
public void paintComponent( Graphics g )
{
super.paintComponent(g);
this.draw( g ); // or inline, or method on subcomponent etc...
}
hth
randy