Solved

debugging

Posted on 2004-04-28
18
184 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
  • 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
pairs challenge 5 45
JAVA part two 5 41
recursion example 16 70
mockito example issue 8 35
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now