Solved

debugging

Posted on 2004-04-28
18
191 Views
Last Modified: 2010-03-31
Hi

Actually in the below code there is one button in a frame .. if I use tooltip for that button it triggers the graphics repaint()  method (rectangle is drawn once more on the same location) .... I need to disable this action ....
that is the tooltip should show the text without repainting() the graphics the screen

does some have have idea kindly forward me

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Frame extends JFrame {
  int vijay=0;
  JPanel contentPane;
  JButton jButton1 = new JButton();
  JPanel jPanel1 = new JPanel();

  public Frame() {
 //   enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();

    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(null);
    this.setSize(new Dimension(601, 511));
    this.setTitle("repaint demo");
    jButton1.setBounds(new Rectangle(89, 60, 105, 55));
    jButton1.setToolTipText("button 1");
    jButton1.setText("jButton1");
    jButton1.addActionListener(new Frame_jButton1_actionAdapter(this));
    jPanel1.setBackground(Color.red);
    jPanel1.setBounds(new Rectangle(240, 67, 277, 374));
    jPanel1.setLayout(null);
    contentPane.add(jPanel1, null);
    jPanel1.add(jButton1, null);
  }
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  public void paint(Graphics g){
    super.paint(g);
    g=this.contentPane.getGraphics();
    vijay++;
    System.out.println("repaints here "+vijay+"   ");
    g.drawRect(15,15,40,40);
  }
void jButton1_actionPerformed(ActionEvent e) {
Graphics g=this.contentPane.getGraphics();

    g.drawRect(15,15,40,40);
  }

}

class Frame_jButton1_actionAdapter implements java.awt.event.ActionListener {
  Frame adaptee;

  Frame_jButton1_actionAdapter(Frame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}
0
Comment
Question by:ragavijayvendra
[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
  • 9
  • 3
  • 2
  • +1
18 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10944638
it can't really, once the tooltip disappears the are it covered needs to be repainted.
0
 
LVL 92

Expert Comment

by:objects
ID: 10944641
>     g=this.contentPane.getGraphics();

you don't need (or want) that line
0
 
LVL 92

Expert Comment

by:objects
ID: 10944645
void jButton1_actionPerformed(ActionEvent e) {
Graphics g=this.contentPane.getGraphics();
    g.drawRect(15,15,40,40);
  }
}


You shouldn't do that.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:ragavijayvendra
ID: 10944715
Thanks for your reply !

I understand after using tooltip it has to repaint .. But in my actual frame i have around more than 40 buttons and each has tool tip and also it has complex graphics
so when i use the tool tip it unnecessary repaints the graphics and my frame flickers for the graphics !


0
 
LVL 92

Expert Comment

by:objects
ID: 10944738
add the following method to fix your flickering:

public void update(Graphics g)
{
   paint(g);
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10944740
Actually that mightn't fix your flickering.
0
 
LVL 92

Expert Comment

by:objects
ID: 10944754
Instead of painting to you frame, I'd suggest instead using a JPanel subclass.
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10944905
flickering occurs due to lack of buffering...u try using DoubleBuffering...

JPanel panel = new JPanel(true); /* true enables DoubleBuffering in JPanel */

in this JPanel in can add ur buttons and then further, the panl can be added to the JFrame
0
 
LVL 92

Expert Comment

by:objects
ID: 10944997
double buffering is already being used.
0
 

Author Comment

by:ragavijayvendra
ID: 10947879
Thanks for your reply !

I have tried but its has the same problem !

is there any possible way to make some flag (checking variable) for the tool tip  in the paint method when the toop tip is trigerred !

for example !!!

 public void paint(Graphics g){
    super.paint(g);
  if(tooltipenabled == false)
  {
    g=this.contentPane.getGraphics();
    vijay++;
    System.out.println("repaints here "+vijay+"   ");
    g.drawRect(15,15,40,40);
  }
  }
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10948474
Hi ragavijayvendra,

Try to override the repaint() method:

public void repaint()
{
    Graphics g=getGraphics();
    if (g==null) super.repaint();
    else paint(g);
}
0
 
LVL 92

Expert Comment

by:objects
ID: 10954640
> is there any possible way to make some flag (checking variable) for the tool tip  in the paint method
> when the toop tip is trigerred !

no

and it shouldn't be a problem. We use tooltips all the time without any problems.
Try instead doing your custom painting on a panel and not your frame as I suggested earlier.
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 11017110
Hi ragavijayvendra,

what's new ? Is your problem solved ?

0
 

Author Comment

by:ragavijayvendra
ID: 11019067
HI Webstorm ,

Thanks for your message ! Actually I have tried your idea but it is not working !

But instead I have delete the Tooltip for all buttons.. after deleting the tool tip there is no such problem

But I am interested in  finding out the solution !

Hi  Object ,

By the way I cannot make a new paint panel Since I am only enhancing the existing project and it already stands around  10000 LOC..... So I don't have the right to change the existing code for making the Tooltip issue !
Kindly Help me for getting a better solution I mean without a new panel for paint

Thanks Object and Webstorm for your Valuable  Help

Friendly,
Vijay
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 11019091
sorry if u can't change the code then I don't think there is any way to solve your problem.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Facing this issue for maven proxy setting 2 45
Java 8 to Java 6 8 44
Java array 21 150
Java Inharitance subclass/child extends, reference variable from base/parent class 9 72
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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

752 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