如题,求解,先谢谢了

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【qiumomo】截止到2008-07-17 22:51:21的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:0                        
    结贴的百分比:0.00  %               结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    重写其public void paintComponents(Graphics g)方法,自己画
      

  3.   

    给你个现成的吧,没写注释,自己慢慢研究
    import java.awt.Color;
    import java.awt.FontMetrics;
    import java.awt.Graphics;
    import java.awt.event.HierarchyBoundsListener;
    import java.awt.event.HierarchyEvent;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;import javax.swing.Action;
    import javax.swing.BorderFactory;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;public class BButton extends JButton implements MouseListener, HierarchyBoundsListener
    {
        private static final long serialVersionUID = -5980379874450229166L;
        
        private int rim = 2;
        
        private int alpha = 3;
        
        protected Icon currentIcon;
        
        protected boolean isEnter = false;
        
        protected boolean isPressed = false;
        
        private boolean defaultButton = false;
        
        public BButton()
        {
            this("", null);
        }
        
        public BButton(Icon icon)
        {
            this("", icon);
        }
        
        public BButton(String text)
        {
            this(text, null);
        }
        
        public BButton(String text, Icon icon)
        {
            super(text, icon);
            init();
        }
        
        public BButton(Action action)
        {
            super(action);
            init();
        }
        
        private void init()
        {
            this.addMouseListener(this);
            this.addHierarchyBoundsListener(this);
            this.setBorder(BorderFactory.createEmptyBorder());
        }
        
        public void setIcon(Icon icon)
        {
            super.setIcon(icon);
            this.currentIcon = icon;
        }
        
        public boolean isDefaultButton()
        {
            return defaultButton;
        }    public void setDefaultButton(boolean defaultButton)
        {
            this.defaultButton = defaultButton;
        }    protected void paintComponent(Graphics g)
        {
            String text = this.getText();
            Icon pressedIcon = this.getPressedIcon();
            
            if(currentIcon != null)
            {
                g.drawImage(((ImageIcon)currentIcon).getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
            }
            
            if(text != null && !text.trim().equals(""))
            {
                FontMetrics fm = getFontMetrics(getFont());
                int x = (getWidth() - fm.stringWidth(text)) / 2;
                int y = (getHeight() - fm.getHeight()) / 2 + 11;
                x = currentIcon == pressedIcon? x + 1: x;
                y = currentIcon == pressedIcon? y + 1: y;
                g.setFont(getFont());
                g.setColor(isEnabled()? new Color(17, 64, 96): Color.GRAY);
                g.drawString(text, x, y);
            }
            
            if(isDefaultButton() && currentIcon != pressedIcon && isEnabled())
            {
                g.setColor(new Color(235, 249, 8));
                g.drawRoundRect(rim, rim, getWidth() - rim * 2, getHeight() - rim * 2, alpha, alpha);
            }
        }
        
        public void setEnabled(boolean b)
        {
            if(!b)
            {
                isEnter = false;
                isPressed = false;
                currentIcon = getIcon();
            }
            
            super.setEnabled(b);
        }
        
        public void mouseEntered(MouseEvent e)
        {
            if(isEnabled())
            {
                isEnter = true;
                currentIcon = isPressed? getPressedIcon(): getRolloverIcon();
            }
        }    public void mouseExited(MouseEvent e)
        {
            if(isEnabled())
            {
                isEnter = false;
                currentIcon = isPressed? getPressedIcon(): getIcon();
                repaint();
            }
        }    public void mousePressed(MouseEvent e)
        {
            if(isEnabled())
            {
                isPressed = true;
                currentIcon = getPressedIcon();
            }
        }    public void mouseReleased(MouseEvent e)
        {
            if(isEnabled())
            {
                isPressed = false;
                currentIcon = isEnter? getRolloverIcon(): getIcon();
            }
        }    public void ancestorMoved(HierarchyEvent e)
        {
            this.repaint();
        }    public void ancestorResized(HierarchyEvent e)
        {}
        
        public void mouseClicked(MouseEvent e)
        {}
    }
      

  4.   

    狂三对swing的研究真透彻啊,代码已经写的不能再清楚了,楼主,可以结贴散分了
      

  5.   

    哈哈,这个帖子没分的~~~~~~~~~~~~Working awesome and behaving low profile!