JPanel上的JButton,能否有方法使JButton在没有把鼠标放上去时就没有JButton在的感觉只有那上面的图标在,当放上去时就明显的看见那JButton的轮廓。就是qq聊天窗口上的那些按钮一样效果。谢谢

解决方案 »

  1.   

    使用Java自带的UI(例如:UIManager)试试看!
      

  2.   

    o ,我刚刚没学java多久,不是很懂啊 ,能明确点不。
      

  3.   

    public class PlatButtonDemo { public static void main(String[] args) {
    JFrame f = new JFrame();
    final Container c = f.getContentPane();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    c.setLayout(new FlowLayout());
    final JButton btn = new JButton("Hello");
    btn.setUI(new BasicButtonUI() {
    protected void paintText(Graphics g, JComponent c,
    Rectangle textRect, String text) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
    int mnemonicIndex = b.getDisplayedMnemonicIndex(); /* Draw the Text */
    if (model.isEnabled()) {
    /*** paint the text normally */
    g.setColor(c.getForeground());
    SwingUtilities2.drawStringUnderlineCharAt(c, g, text,
    mnemonicIndex, textRect.x + getTextShiftOffset(),
    textRect.y + fm.getAscent() + getTextShiftOffset());
    } else {
    /*** paint the text disabled ***/
    g.setColor(c.getBackground().brighter());
    SwingUtilities2.drawStringUnderlineCharAt(c, g, text,
    mnemonicIndex, textRect.x, textRect.y
    + fm.getAscent());
    g.setColor(b.getBackground().darker());
    SwingUtilities2.drawStringUnderlineCharAt(c, g, text,
    mnemonicIndex, textRect.x - 1, textRect.y
    + fm.getAscent() - 1);
    }
    }
    });
    btn.setBackground(c.getBackground());
    final Border border = btn.getBorder();
    btn.setBorder(BorderFactory.createEmptyBorder());
    btn.setOpaque(false); btn.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseEntered(MouseEvent e) {
    btn.setBorder(border);
    } @Override
    public void mouseExited(MouseEvent e) {
    btn.setBorder(BorderFactory.createEmptyBorder());
    }
    }); c.add(btn);
    f.setSize(200, 200);
    f.setVisible(true);
    }
    }
      

  4.   

    可以的,是开始时设置button的setEnable(false),真正用到得时候在设置为true,即setEnable(true)
    你试试这样
      

  5.   

    应该可以的,LZ你要实现什么没说清楚,焦点Focuse设置。