imageicon

Adding image in JApplet

旧巷老猫 提交于 2019-12-19 09:52:15
问题 ImageIcon icon= new ImageIcon("a.gif"); JLabel jLabel1=new JLabel(icon); jLabel1.setVisible(true); card1.add(jLabel1); I am a newbie to Java and I am facing a problem to add image in a panel in applet. My image is in the same folder. My applet is visible without any problem but only image is not displayed. 回答1: public void init() URL imageURL = new URL(getDocumentBase(), "a.gif"); Image image = getImage(imageURL); ImageIcon icon = new ImageIcon(image); // ... The ImageIcon constructor that

Auto-resizing JButton Icon

落爺英雄遲暮 提交于 2019-12-19 00:37:33
问题 so I have this JButtons to which I add Icons. The Icons are too large initially, so I resize them beforehand, and it works fine. Except that when I resize the window, the JButtons change size, but not the Icons, which is problematic. Is there a way to have an Icon just fill the JButton it is attached to? Bit of code to make it clearer: public JewelClass(){ setBackground (new Color (30,30,30)); addActionListener(this); setLayout(new GridLayout()); ImageIcon icon = new ImageIcon(src/carre.jpg);

How to change java icon in a JFrame

十年热恋 提交于 2019-12-18 13:15:33
问题 Ok so I've been researching this one quiet a bit. I am fairly new to java but thought that this one would be easy. Ive tried just about every way that has been answered on this site and still no luck, and usually when I look here I am able to find a answer that fits what I am looking for. Does anyone know how to change the Java icon in the top corner of the JFrame. I'm pretty positive that its not my file path either because all my images are in the same folder and they all work, this is the

Loading Icon resource error

青春壹個敷衍的年華 提交于 2019-12-18 09:07:21
问题 In Eclipse, when I run the code, this works: import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("test viewing images"); frame.setSize(600,300); frame.setLocationRelativeTo(null); // centered on monitor frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /** * Menu Bar stuff */ JMenuBar menuBar; JMenu menu; JMenuItem

Animated GIF on a JButton, play it when mouse is hovered

假装没事ソ 提交于 2019-12-18 06:47:27
问题 Icon icon = new ImageIcon(getClass().getResource( "/img/icon.gif" ) ); aButton = new JButton("Its a button", icon); Is there some kind of method that can stop an animated from playing? I was thinking of assigning a static jpg of the gif, then when I hover, assign the animated gif, but I don't think there is an event for taking off mouse in MouseMotionListener so I can load back the static jpg. The gif loops in the button, however, if I hover over it, it disappears. How can I make the gif

Animated GIF on a JButton, play it when mouse is hovered

守給你的承諾、 提交于 2019-12-18 06:46:25
问题 Icon icon = new ImageIcon(getClass().getResource( "/img/icon.gif" ) ); aButton = new JButton("Its a button", icon); Is there some kind of method that can stop an animated from playing? I was thinking of assigning a static jpg of the gif, then when I hover, assign the animated gif, but I don't think there is an event for taking off mouse in MouseMotionListener so I can load back the static jpg. The gif loops in the button, however, if I hover over it, it disappears. How can I make the gif

Converting an ImageIcon to a BufferedImage

左心房为你撑大大i 提交于 2019-12-18 04:08:35
问题 I've been trying to convert a ImageIcon to BufferedImage ... And I've had no luck. I have a pre-existing ImageIcon that needs to be converted to a Buffered Image for the vast amount of BufferedImage operations that exist. I have found a few ways, but all of them are hugely CPU intensive. 回答1: What's wrong with: BufferedImage bi = new BufferedImage( icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); // paint the Icon to the BufferedImage.

not redisplaying an image s

99封情书 提交于 2019-12-17 21:18:40
问题 Hi everybody I am a bit of stack here. When I run the program and press the button submit it is supposed to change 4 pictures in every 2 seconds.However it is not redisplaying the images. If anyone can give me a hand it would be great. I am using eclipse and the program is compiling and running. Here is the code. /** Here is the GUI of the program * class name SlideShowGui.java * @author Kiril Anastasov * @date 07/03/2012 */ import java.awt.*; import java.awt.event.ActionEvent; import java

Displaying an ImageIcon

做~自己de王妃 提交于 2019-12-17 20:52:34
问题 I am trying to display an image on a JPanel . I'm using an ImageIcon for rendering the image, and the image is in the same directory as the class file. However, the image is not being displayed, and there are no errors occuring. Could anyone please assist in working out what's wrong with my code... package ev; import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JPanel; public class Image extends JPanel { ImageIcon image = new ImageIcon("peanut.jpg"); int x = 10; int y =

java swing resize ImageIcon according to jLabel

南楼画角 提交于 2019-12-17 20:38:02
问题 i am a new programmer here and i have something to ask, i have browse a picture into my GUI (and set the path in text box also)which displays on a Label, but the label dimension is set only 100,100 while the picture is much bigger so when i open/display it into the label it get cropped , is there anyway to make it auto resize to the label size? below is my logic code on browse button and open dialog box please any one tell me where i am wrong.. public class ImagePath extends javax.swing