当MouseOver"鼠标悬停在它上面时如何放大JButton图像"

时间:2015-07-10 13:42:38

标签: java swing mouseevent jbutton

几乎是我的"开始"当我将鼠标悬停在它上面时按钮不会放大。 这是我的代码下面的任何想法为什么它不会?如果能给我看一个真正有用的示例代码! :)"我对Java也很陌生"这就是为什么示例代码会更好地帮助我提前感谢!

public class Window extends JFrame implements MouseListener {

private static final long serialVersionUID = 1L;
private static JButton button;
private static JFrame frame = new JFrame("Scroller Runner v0.2.0");

public static void main(String[] args) throws IOException {
    new Window();
    JButton button = new JButton();
    JTextPane TEXT = new JTextPane();
    BufferedImage buttonIcon;
    button = new JButton(new ImageIcon("C:\\Users\\GOULDEN\\Desktop\\MENU_START.png"));
    button.setBorder(BorderFactory.createEmptyBorder());
    button.setContentAreaFilled(false);
    button.setBounds(490, 250, 300, 75);
    button.setCursor(new Cursor(Cursor.HAND_CURSOR));
    button.addMouseListener(null);

    frame.setSize(1280, 720);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setResizable(false);
    frame.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("C:\\Users\\GOULDEN\\Desktop\\MAIN_MENU.png")))));
    frame.pack();
    frame.add(button);
    frame.setVisible(true);
}@Override
public void mouseEntered(MouseEvent e) {
    button.setBounds(550, 300, 300, 75);
    this.repaint();
}

3 个答案:

答案 0 :(得分:0)

这段代码适合我。

如果您想更改尺寸,setSize()更适合这种情况。

    button.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {                
            button.setSize(WIDTH,HEIGHT);                
        }
    });

答案 1 :(得分:0)

取代:

class YourModel < ActiveRecord::Base
  ...

  after_validation {
    retain_specified_errors(%i(attr another_att))
  }

  def retain_specified_errors(attrs_to_retain)
    errors.each do |attr|
      unless attrs_to_retain.include?(attr)
        errors.delete(attr)
      end
    end
  end
end

使用:

button.setBounds(550, 300, 300, 75);

答案 2 :(得分:0)

尝试使用附加代码为我工作

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">Hello</div>