Article View: borland.public.jbuilder.java.swing
Article #8877Re: Paintproblem
From: Stephan Klaffer
Date: Mon, 10 Jul 2000 00:00
Date: Mon, 10 Jul 2000 00:00
222 lines
6033 bytes
6033 bytes
I think the problem you have is because you are using a AWT button and a
swing-based menu. If that is right, then the solution is to set the
setLightWeightPopupEnabled property on your menus to false.
Stephan
"sven goetgeluck" <sven@officeline.be> wrote in message
news:39698078.B0D4C320@officeline.be...
Hi have designd a "button" that extends a canvas for drawing imagebuttons
like in ie and sort so when you enter with mouse or click other imgages are
displayed on the button but when implenting them in application into my
buttonbar something weird happens
the buttons look great but when clikking on the menu above them them come ,
display trough the menu
what can this be
greeting Sven
see source :
import java.awt.event.*;
import java.awt.image.*;
import java.net.*;
import java.awt.*;
public class ImageButton extends Canvas
protected ActionListener actionListener = null;
int w,h;
boolean clicked;
boolean down;
boolean enabled;
boolean inside;
Image UPimage;
Image DOWNimage;
Image Dissableimage;
Image disabledimage;
public ImageButton(String up_b, String down_b)
clicked=false;
down=false;
enabled=true;
InitImage(up_b,down_b);
setSize(w,h);
addMouseListener(new ImageButtonMouseListener());
addMouseMotionListener(new ImageButtonMouseMotionListener());
}
public void InitImage(String up, String down)
MediaTracker tracker;
try
ImageIcon upimage = new ImageIcon(up);
ImageIcon downimage = new ImageIcon(down);
UPimage = upimage.getImage();
// UPimage = getToolkit().getImage(up);
DOWNimage = downimage.getImage();
// DOWNimage = getToolkit().getImage(down);
tracker = new MediaTracker(this);
tracker.addImage(UPimage,0);
tracker.addImage(DOWNimage,1);
tracker.waitForAll();
}
catch (InterruptedException e)
e.printStackTrace();
}
disabledimage=createImage(new FilteredImageSource
(UPimage.getSource(),new ImageButtonDisableFilter()));
w=UPimage.getWidth(this);
h=UPimage.getHeight(this);
}
public void paint(Graphics g)
/* if (down)
g.drawImage(DOWNimage,0,0,this);
}
else
if (enabled)
g.drawImage(UPimage,0,0,this);
}
else
g.drawImage(disabledimage,0,0,this);
}
}
*/
if (inside && !down && UPimage != null)
g.drawImage(UPimage,0,0,null);
}
else if (down)
g.drawImage(DOWNimage,0,0,this);
}
else
g.drawImage(disabledimage,0,0,this);
}
}
public void setEnabled(boolean b)
enabled=b;
repaint();
}
public boolean isEnabled()
return (enabled);
}
public void addActionListener(ActionListener l)
actionListener =
AWTEventMulticaster.add(actionListener,l);
}
public void removeActionListener(ActionListener l)
actionListener =
AWTEventMulticaster.remove(actionListener, l);
}
public class ImageButtonMouseListener extends MouseAdapter
public void mouseEntered(MouseEvent e)
inside = true;
repaint();
}
public void mouseExited(MouseEvent e)
inside = false;
repaint();
}
public void mousePressed(MouseEvent e)
Point p = e.getPoint();
if ((p.x < w)&&(p.y < h)&&(p.x > 0)&&(p.y > 0)&&(enabled==true))
clicked=true;
down=true;
repaint();
}
}
public void mouseReleased(MouseEvent e)
Point p = e.getPoint();
if (down)
down=false;
repaint();
}
if ((p.x < w)&&(p.y < h)&&(p.x > 0)&&(p.y > 0)&&(clicked==true))
ActionEvent ae =
new ActionEvent(e.getComponent(),0,"click");
if (actionListener != null)
actionListener.actionPerformed(ae);
}
}
clicked=false;
}
}
public class ImageButtonMouseMotionListener extends
MouseMotionAdapter
public void mouseEntered(MouseEvent e)
System.out.println("Enetered");
}
public void mouseDragged(MouseEvent e)
Point p = e.getPoint();
if ((p.x < w)&&(p.y < h)&&(p.x > 0)&&(p.y > 0)&&(clicked==true))
if (down==false)
down=true;
repaint();
}
}
else
if (down==true)
down=false;
repaint();
}
}
}
}
public Dimension getPreferredSize()
return (new Dimension(UPimage.getWidth(this),
UPimage.getHeight(this)));
}
public Dimension getMinimumSize()
return getPreferredSize();
}
class ImageButtonDisableFilter extends RGBImageFilter
public ImageButtonDisableFilter()
canFilterIndexColorModel=true;
}
public int filterRGB(int x, int y, int rgb)
return (rgb & ~0xff000000) | 0x80000000;
}
}
}
Technical Details
Message-ID:
<963242589.6841.0.nnrp-10.c29f1f7c@news.demon.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39698078.B0D4C320@officeline.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,1ac40abb3e2e6f3 X-Google-Attributes: gid111d45,public From: "Stephan Klaffer" <stephan.klaffer@decisionworks.co.uk> Subject: Re: Paintproblem Date: 2000/07/10 Message-ID: <963242589.6841.0.nnrp-10.c29f1f7c@news.demon.co.uk> X-Deja-AN: 644635134 X-NNTP-Posting-Host: [194.159.31.124]:194.159.31.124 References: <39698078.B0D4C320@officeline.be> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 963242589 nnrp-10:6841 NO-IDENT [194.159.31.124]:194.159.31.124 X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing