Article View: borland.public.jbuilder.java.swing
Article #8680Re: explorer like button in bar
From: Nils Olav Sel�sdal
Date: Mon, 31 Jul 2000 00:00
Date: Mon, 31 Jul 2000 00:00
166 lines
4955 bytes
4955 bytes
The Image that does the exploere like borders??
;(
sven goetgeluck <sven@officeline.be> wrote in message
news:39800C6D.5F50F4A7@officeline.be...
> Hi , i have made an button like in windows explorer with mouse over
> capabilities
> he works fine in an panel , but when trying it into the buttonbar he
> doesn't show like it should be , the does not paint completely , but
> works fine
> paints only parts of the button
>
> how can this be solved ?
> enclosed the source of the button below
>
> greetings sven
>
>
>
> package vrex4;
> import java.awt.Graphics;
> import javax.swing.*;
> import java.awt.event.*;
> import java.awt.Image;
> import java.awt.Component;
> import java.awt.*;
> import java.awt.event.*;
> import java.awt.image.*;
> import java.net.*;
> import java.awt.*;
>
>
>
> public class MyExplorerImageButton extends JButton{
>
> private String upimage = null;
> private String downimage = null;
> Image DISimage = null;
> Image UPimage = null;
> Image DOWNimage = null;
> boolean inside = false;
> boolean press = false;
> int w,h;
>
>
> public MyExplorerImageButton() {
> try {
> jbInit();
> }
> catch(Exception e) {
> e.printStackTrace();
> }
> }
> public MyExplorerImageButton(String up_b, String down_b)
> {
> upimage = new String(up_b);
> downimage = new String (down_b);
> try {
> jbInit();
> }
> catch(Exception e) {
> e.printStackTrace();
> }
>
> }
>
>
> public void paint(Graphics g) {
> //TODO: override this javax.swing.JComponent method;
> super.paint( g);
> Dimension dim = this.getPreferredSize();
>
> if (inside && !press && UPimage != null) {
> g.drawImage(UPimage,0,0,dim.width,dim.height,null);
> }
> else if (press) {
> g.drawImage(DOWNimage,0,0,dim.width,dim.height,null);
> }
> else
> {
> g.drawImage(DISimage,0,0,dim.width,dim.height,null);
>
> }
> }
>
> private void jbInit() throws Exception {
> ImageIcon upImage = new ImageIcon(upimage);
> UPimage = upImage.getImage();
> ImageIcon downImage = new ImageIcon(downimage);
> DOWNimage = downImage.getImage();
> ImageFilter colorfilter = new GrayFilter();
> DISimage = createImage( new
> FilteredImageSource(UPimage.getSource(),colorfilter));
> // this.setBorderPainted(false);
> // this.setFocusPainted(false);
>
> this.addMouseListener(new java.awt.event.MouseAdapter() {
>
> public void mousePressed(MouseEvent e) {
> this_mousePressed(e);
> }
>
> public void mouseEntered(MouseEvent e) {
> this_mouseEntered(e);
> }
>
> public void mouseExited(MouseEvent e) {
> this_mouseExited(e);
> }
>
> public void mouseReleased(MouseEvent e) {
> this_mouseReleased(e);
> }
> });
> }
>
> void this_mousePressed(MouseEvent e) {
> press=true;
> repaint();
> }
>
> void this_mouseEntered(MouseEvent e) {
> inside = true;
> repaint();
> }
>
> void this_mouseExited(MouseEvent e) {
> inside = false;
> repaint();
> System.out.println("out");
> }
>
> void this_mouseReleased(MouseEvent e) {
> press = false;
> repaint();
> }
> public Dimension getPreferredSize() {
> return (new Dimension(UPimage.getWidth(this),
> UPimage.getHeight(this)));
> }
>
> public Dimension getMinimumSize() {
> return getPreferredSize();
> }
>
> class GrayFilter extends RGBImageFilter {
>
> public GrayFilter() {
> // If I set ture, black is gone?!
> //canFilterIndexColorModel = true;
> }
>
> public int filterRGB(int x, int y, int rgb) {
> int r = (rgb & 0xff0000) >> 16;
> int g = (rgb & 0x00ff00) >> 8;
> int b = (rgb & 0x0000ff);
> int iy = (int)(r + g + b)/3;
> iy = Math.min(255, iy);
> return ((rgb & 0xff000000)
> | (iy << 16)
> | (iy << 8)
> | iy);
> }
> }
> }
>
Technical Details
Message-ID:
<1ydh5.25252$MS3.419949@news1.online.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39800C6D.5F50F4A7@officeline.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,3f23a3acd0ddca99 X-Google-Attributes: gid111d45,public From: "Nils Olav Sel�sdal" <noselasd@frisurf.no> Subject: Re: explorer like button in bar Date: 2000/07/31 Message-ID: <1ydh5.25252$MS3.419949@news1.online.no> X-Deja-AN: 652725045 References: <39800C6D.5F50F4A7@officeline.be> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Complaints-To: news-abuse@online.no X-Trace: news1.online.no 965043453 130.67.114.81 (Mon, 31 Jul 2000 13:37:33 MET DST) Organization: Telenor Online Public Access X-MSMail-Priority: Normal NNTP-Posting-Date: Mon, 31 Jul 2000 13:37:33 MET DST Newsgroups: borland.public.jbuilder.java.swing