imageicon

Sizes of frame icons used in Swing

不问归期 提交于 2019-11-26 10:34:21
We can use a list to initialise the window icons using Window.setIconImages(List<? extends Image>) . What are the different sizes of icons typically used for in a JFrame ? Code This code turns 64 different sized images (from 16x16, incrementing by 2) into icons for the list. import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Vector; import javax.swing.*; import javax.swing.border.EmptyBorder; public class FrameIconList { public static BufferedImage getImage(int size, Color color) { BufferedImage i = new BufferedImage( size, size, BufferedImage

Java GIF animation not repainting correctly

蹲街弑〆低调 提交于 2019-11-26 09:58:04
问题 I\'m trying to animate a GIF image. The animation works, but it\'s not painting well. It shows like this (non-animated screenshot): In the image, the tail wags like this: As you can see, the image does not repaint well. I don\'t want to use JLabels but that did not work correctly, so I followed this question when my image did not animate. My code is like this: public void draw(JPanel canvas, Graphics2D g2d, int x, int y) { getFrontImage().paintIcon(canvas, g2d, x, y); } Where the image is

Spring behavior simulation

一笑奈何 提交于 2019-11-26 08:35:54
问题 Basically, i want to simulate spring behavior on painted image. I want to make it run through a few iterations scaling it up and down (like it is fixed on a spring). All of the examples i found on the net lead to this class - FloatSpring.java It should provide the needed calculations to move point A to point B applying spring-like effect which depends on various FloatSpring class settings. The problem is that i didn\'t find a single clear example how to use it properly. I made this small

JLabel images array

蓝咒 提交于 2019-11-26 05:21:36
I am trying to load the same jlabel stored image twice into a gridlayout panel, however instead of creating two instances of the image, the image is only displayed once then moved. How can I store the same JLabel position in the pieces array into more than one JLabel in the boardLabels array. Thanks :) public static JPanel boardPanel = new JPanel(new GridLayout(4, 0)); public static JLabel pieces[] = new JLabel[2]; private static JLabel[] boardLabels = new JLabel[4]; public MainFrame() { pieces[0] = new JLabel(new ImageIcon(System.getProperty("user.dir") + "/images/piece1.png")); pieces[1] =

Java in Eclipse: Where do I put files on the filesystem that I want to load using getResource? (e.g. images for an ImageIcon)

Deadly 提交于 2019-11-26 04:45:47
I know the file needs to be where the getClass().getResource(filename) can find it, but I don't know where that is. I'm interested both in where to put the files on the filesystem itself, and how to go about using Eclipse's functionality to set up the resources. For Eclipse, typically all you need to do is set up a folder somewhere within your source code directory. For instance, if the directory containing your source is /src then you can create a /src/resources folder to place your images/files in. Then, within your class you do a getResource("/resources/image.png") to retrieve it. You can

How to set Icon to a JLabel from an image from a folder?

天大地大妈咪最大 提交于 2019-11-26 03:45:10
问题 I am trying to set an icon to a JLabel from a folder of images whenever an item is selected from a JComboBox. The name of items in the JComboBox and name of the images in the folder are same. So whenever an item is selected from the JComboBox, the corresponding image with the same name should be set as an icon to the JLabel. I am trying to do something like this. private void cmb_movieselectPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt){ updateLabel(cmb_moviename

JLabel images array

こ雲淡風輕ζ 提交于 2019-11-26 03:25:31
问题 I am trying to load the same jlabel stored image twice into a gridlayout panel, however instead of creating two instances of the image, the image is only displayed once then moved. How can I store the same JLabel position in the pieces array into more than one JLabel in the boardLabels array. Thanks :) public static JPanel boardPanel = new JPanel(new GridLayout(4, 0)); public static JLabel pieces[] = new JLabel[2]; private static JLabel[] boardLabels = new JLabel[4]; public MainFrame() {

Sizes of frame icons used in Swing

天涯浪子 提交于 2019-11-26 02:11:02
问题 We can use a list to initialise the window icons using Window.setIconImages(List<? extends Image>). What are the different sizes of icons typically used for in a JFrame ? Code This code turns 64 different sized images (from 16x16, incrementing by 2) into icons for the list. import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Vector; import javax.swing.*; import javax.swing.border.EmptyBorder; public class FrameIconList { public static

Java in Eclipse: Where do I put files on the filesystem that I want to load using getResource? (e.g. images for an ImageIcon)

烂漫一生 提交于 2019-11-26 01:53:59
问题 I know the file needs to be where the getClass().getResource(filename) can find it, but I don\'t know where that is. I\'m interested both in where to put the files on the filesystem itself, and how to go about using Eclipse\'s functionality to set up the resources. 回答1: For Eclipse, typically all you need to do is set up a folder somewhere within your source code directory. For instance, if the directory containing your source is /src then you can create a /src/resources folder to place your

Java Swing: Displaying images from within a Jar

假装没事ソ 提交于 2019-11-26 00:22:44
问题 When running a Java app from eclipse my ImageIcon shows up just fine. But after creating a jar the path to the image obviously gets screwed up. Is there a way to extract an image from the jar at runtime so I can then open it up? Or, is there a better way to do this? I\'d like to distribute a single jar file if possible. 回答1: To create an ImageIcon from an image file within the same jars your code is loaded: new javax.swing.ImageIcon(getClass().getResource("myimage.jpeg")) Class.getResource