Java JButton的问题
我有一些JButton的代码:Java JButton的问题,java,swing,jbutton,Java,Swing,Jbutton,我有一些JButton的代码: solutionButton = new JButton("Solution"); solutionButton.setBorderPainted( false); solutionButton.setContentAreaFilled( false ); solutionButton.setFocusPainted( false); solutionButton.setFont( new Font("Arial",Font.BOLD,16)); so
solutionButton = new JButton("Solution");
solutionButton.setBorderPainted( false);
solutionButton.setContentAreaFilled( false );
solutionButton.setFocusPainted( false);
solutionButton.setFont( new Font("Arial",Font.BOLD,16));
solutionButton.setForeground( new Color(80,21,25));
solutionButton.setRolloverIcon(
new ImageIcon(getClass().getResource( "images/game.png")));
solutionButton.setRolloverEnabled( true );
add(solutionButton);
如果我只是设置图标,它工作正常,我看到图标。如果我执行上述操作并尝试设置滚动图标,则在鼠标悬停按钮时不会看到任何图标
我做错了什么
谢谢指向月亮!
有没有一种方法可以做到这一点而不首先设置一个图标,我只想要一个滚动图标,而不是一个图标太 指向太空(有很多)! 指向月亮!
有没有一种方法可以做到这一点而不首先设置一个图标,我只想要一个滚动图标,而不是一个图标太 指向太空(有很多)!
比较这个。比较这个。有没有办法不先设置图标就可以做到这一点,我只想要一个滚动图标而不是图标。有没有办法不先设置图标就可以做到这一点,我只想要一个滚动图标而不是图标。
import java.awt.Image;
import javax.swing.*;
import javax.imageio.ImageIO;
import java.net.URL;
class TestRolloverIcon {
public static void main(String[] args) throws Exception {
URL url1 = new URL("http://pscode.org/media/citymorn1.jpg");
URL url2 = new URL("http://pscode.org/media/citymorn2.jpg");
final Image image1 = ImageIO.read(url1);
final Image image2 = ImageIO.read(url2);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JButton button = new JButton("Point at the Moon!");
button.setIcon(new ImageIcon(image1));
button.setRolloverIcon(new ImageIcon(image2));
JOptionPane.showMessageDialog(null, button);
}
});
}
}
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.imageio.ImageIO;
import java.net.URL;
class TestRolloverIcon {
public static void main(String[] args) throws Exception {
URL url2 = new URL("http://pscode.org/media/citymorn2.jpg");
final BufferedImage image2 = ImageIO.read(url2);
final BufferedImage image1 = new BufferedImage(
image2.getWidth(),image2.getHeight(),BufferedImage.TYPE_INT_ARGB);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JButton button = new JButton("Point at space (there's a lot of it)!");
button.setIcon(new ImageIcon(image1));
button.setRolloverIcon(new ImageIcon(image2));
JOptionPane.showMessageDialog(null, button);
}
});
}
}