imageicon

Showing part of an ImageIcon

南笙酒味 提交于 2019-12-23 03:12:22
问题 Bonjour, I'm trying my hand at animation, and have found myself a strip of explosions on a single image in a row. I want them to show one after the other in sequence to animate an explosion. Naturally, I'm thinking ImageIcon on JLabel , but when I looked at the JLabel spec I found this line: JLabel(Icon icon) -- Creates a JLabel instance with the specified image. The label is centered vertically and horizontally in its display area. I want to be able to show only part of a full image in the

Showing part of an ImageIcon

送分小仙女□ 提交于 2019-12-23 03:12:06
问题 Bonjour, I'm trying my hand at animation, and have found myself a strip of explosions on a single image in a row. I want them to show one after the other in sequence to animate an explosion. Naturally, I'm thinking ImageIcon on JLabel , but when I looked at the JLabel spec I found this line: JLabel(Icon icon) -- Creates a JLabel instance with the specified image. The label is centered vertically and horizontally in its display area. I want to be able to show only part of a full image in the

getResource() -> Source not found

我们两清 提交于 2019-12-23 01:04:48
问题 I'm following the tutorial here. The file is in the same root folder of the project. I've tried doing it when it's in the src folder and in the same package folder. None of those 3 locations worked. The specific line of code is: ImageIcon ii = new ImageIcon(this.getClass().getResource("bardejov.jpg")); Any idea what I'm doing wrong? 回答1: // absolute from the classpath MyClass.class.getResource("/myfolder/abc.txt"); // relative to the class location MyClass.class.getResource("abc.txt"); //

Animated ImageIcon as Button

旧巷老猫 提交于 2019-12-22 08:48:50
问题 I have an imageIcon as Button, now i would to animate it when you rollover. I tried to use a animated gif (without loop) on setRolloverIcon(Icon). But when i hover again on the button the gif is not playing again. When i use a looped gif then it plays it from a random frame. I tried using paintComponent to draw a Shape or an image as Button, which works fine, but even when i use setPreferredSize() or setSize() or setMaximumSize() the Button uses its default size, as you can see in the picture

Java: ImageIcon vs. Image difference

六眼飞鱼酱① 提交于 2019-12-22 03:20:00
问题 Could anyone explain to me in noob way what the difference is betweeen ImageIcon and Image classes/objects in Java? Thanks 回答1: Their nature and application is different. Image is an abstract superclass of all classes that represent graphical images. ImageIcon is an implementation of Icon interface that uses Image as its source. Edit: Think of an Image as something that could be rendered and an ImageIcon as something that will be rendered as an Icon when its paintIcon() method is called. Edit

ImageIcon does not work with me

瘦欲@ 提交于 2019-12-20 07:22:30
问题 i wrote very simple code to display an icon of the grapes but still the code doesn't show me anything here is my code import javax.swing.*; import java.awt.*; public class Code { ImageIcon ii = new ImageIcon("image/grapes2.jpg"); JLabel label = new JLabel("Grapes", ii, SwingConstants.CENTER); JFrame frame = new JFrame("ImageIcon"); public void ui(){ label.setHorizontalTextPosition(SwingConstants.CENTER); label.setVerticalTextPosition(SwingConstants.BOTTOM); label.setIconTextGap(5); label

Using an image for the background of a JPanel and JButton

早过忘川 提交于 2019-12-20 06:39:59
问题 I am trying to use an image I made in photoshop as the background for my GUI. How do I do that? also I made some images I want to display in the button backgrounds after the action is performed... 回答1: For the JButton, use this: JButton button = new JButton("Button Name", new ImageIcon("foo.png"); The Panel is a bit more interesting. This is a good method, though: ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage()); 来源: https://stackoverflow.com/questions/8373006/using-an

Different imageIcon in different cells in JTable

大城市里の小女人 提交于 2019-12-20 04:29:04
问题 I think I got the imageIcon to show up differently in each cell but for some reason when I compile it, the images don't show up. It displays the name of the image but the image itself doesn't show up. Here is an image. http://i49.tinypic.com/r9ibrn.jpg public class movies extends JFrame { public movies() { initComponents(); } private void initComponents() { panel = new JPanel(); logo = new JLabel(); pane = new JScrollPane(); setDefaultCloseOperation(EXIT_ON_CLOSE); setBackground(new Color(255

how to set an image for jtable fixed column, when i am running, it's getting an image path only

好久不见. 提交于 2019-12-19 11:05:20
问题 I created a program to set an imageIcon in jtable fixed column, i created a jtable and getting a database records, then set a first column as fixed column. i set an image icon in fixed column. when i am compiling this program, i am getting only a path of the imageicon not getting an image. I fixed an imageIcon in project package folder. This is the code i used public void Frm_FlxD_Database() { try{ TmpRow=0; TmpMainPrj.PRJ_DB_CONNECTION_ASSGN(); TmpFlxMdl =(DefaultTableModel)FlxD.getModel();

Adding image in JApplet

女生的网名这么多〃 提交于 2019-12-19 09:52:48
问题 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