Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-12-2010, 11:16 PM
Member
 
Join Date: Jul 2009
Posts: 8
Rep Power: 0
shawleigh17 is on a distinguished road
Default Java Popup .hide() method is leaving a grey box in the shape of the JTextArea I use.
Hi, I am trying to have a comment box show up when I move into an area on a canvas, and then hide when I move out of this area. I have a short piece of code that kind of shows the problem I am having... In the example, the popup is having problems with the hiding. In my version (which is much longer and is reliant on 5 or more other long classes ), I can get the popup to show up where I want it to, and I can get all of the text to hide, but I can't get the little gray box to go away. If I use a timer, though, I have no problems. Does any one know why this is happening?

Here is the executable code:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;

public class newClass extends JPanel {
    Rectangle rect = new Rectangle(100,100,150,75);
    MouseoverDetails comments;
    JTextArea popupLabel;
    
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(Color.blue);
        g2.draw(rect);
    }

    public void setRect(int x, int y) {
        rect.setLocation(x, y);
        repaint();
    }

    public static void main(String[] args) {
        newClass test = new newClass();
        new GraphicDragController(test);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(test);
        f.setSize(400,400);
        f.setLocation(100,100);
        f.setVisible(true);
    }
}

class GraphicDragController extends MouseInputAdapter {
    newClass component;
    Point offset = new Point();
    boolean dragging = false;

    public GraphicDragController(newClass gdad) {
        component = gdad;
        component.addMouseListener(this);
        component.addMouseMotionListener(this);
    }

    public void mousePressed(MouseEvent e) {
        Point p = e.getPoint();
        Rectangle r = component.rect;
        if(r.contains(p)) {
            offset.x = p.x - r.x;
            offset.y = p.y - r.y;
            dragging = true;
        }
    }


    public void mouseReleased(MouseEvent e) {
        dragging = false;
    }
    
    public void mouseMoved(MouseEvent e) 
    {
    	boolean inside = false;
   
    	if(component.rect.contains(e.getPoint()))
    	{
		  inside = true;
		  component.popupLabel = new JTextArea("Test");
		  component.comments = new MouseoverDetails(component,e.getPoint(), component.popupLabel);
	    }
   
 	   if (inside == false)
 	   {	   
 		   try{
 			   component.comments.popup.hide();
 		   }
 		   catch(Exception ex){}
 	   }	   
    }

    public void mouseDragged(MouseEvent e) {
        if(dragging) {
            int x = e.getX() - offset.x;
            int y = e.getY() - offset.y;
            component.setRect(x, y);
        }
    }
}

class MouseoverDetails 
{
	PopupFactory factory;
	Popup popup;
	JTextArea popupLabel; 
	
	public MouseoverDetails(newClass test, Point p, JTextArea popupLabel)
	{
		factory = PopupFactory.getSharedInstance();
		popup = factory.getPopup(test, popupLabel, test.rect.x+30, test.rect.y - 30);
		popup.show();
	}	 	
}
and here are the code segments that I am using in my code:
This is the mouseMoved method
Code:
public void mouseMoved(MouseEvent e)
   {
	   boolean insidePallet = false;
	   for(int i=0;i<usedPalletsList.size();++i)
	   {
		  PalletType pt = usedPalletsList.get(i);
		  
		  if(pt.contains(e.getPoint()))
		  {
			  insidePallet = true;
			  comments = new MouseoverDetails(usedPalletsList, e.getPoint(), component, component.addPM.popupLbl);
		  }
	   }
	   
	   if (insidePallet == false)
	   {	   
		   try{
			   comments.popup.hide();
		   }
		   catch(Exception ex){}
		   
	   }	   
   }

And this is part of the class where I implement the popup.
Code:
if(pt.GetType(pt).equals("SinglePallet")&& pt.contains(p) && !r.contains(p) && !pt.text.equals("xxx"))
			{
			    popupLabel.setText("Location: " + currentLocation + "\nDescription: " + skuDescp + "\nVelocity: " + 
					   z + " Pallets Per Week" + "\nBulk Percent: " + bpD 
					   + "%\nOther Percent: " + opD + "%\nBrand: " + brand + 
					   "\nSize: " + group + "\nPlanogram: " + planogram);
			     
			     factory = PopupFactory.getSharedInstance();	
			     popX = pt.x +30;
			     popY = pt.y;
			     popup = factory.getPopup(dndTest, popupLabel, popX, popY);
		    	 popup.show();
		}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-13-2010, 12:11 AM
Steve11235's Avatar
Senior Member
 
Join Date: Dec 2008
Posts: 1,028
Rep Power: 3
Steve11235 is on a distinguished road
Default
Just a quick thought. When you hide the text box, the component under it may not be aware that it needs to repaint itself. After you hide the text box, try revalidate() on the component below...
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-13-2010, 04:54 AM
Senior Member
 
Join Date: Aug 2009
Location: Pittsburgh, PA
Posts: 266
Rep Power: 2
zweibieren is on a distinguished road
Default
There are a number of problems in the sample program.

- Every time the mouse moves while it is inside rect, a new popup is popped up.
All these popups are put in the same place, so there multiplicity is not apparent
- hide() is only called when the mouse is outside the rectangle
and then it only hides the last of the popups that were created
- the popups are placed relative to the screen origin
and not relative to the window or the rect

The sample program does not demonstrate the alleged problem in the full code.

(and revalidate() is concerned with screen placement, so I don't think it will help with repaint problems)

Please try again.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to clear the session when leaving a page. shivakumari Java Servlet 3 03-25-2009 06:25 AM
Grey Box mja229 New To Java 2 12-24-2008 07:24 PM
how we get popup window in java baserohit Advanced Java 1 03-22-2008 04:39 AM
java : how to hide application icon from a task bar yogeshagashe Advanced Java 0 03-12-2008 01:05 PM
Popup in Java fernando New To Java 1 08-07-2007 06:55 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 09:06 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org