imageicon

java swing resize ImageIcon according to jLabel

僤鯓⒐⒋嵵緔 提交于 2019-11-28 12:38:27
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.JFrame { private JPanel contentPane; JLabel jLabel1; String s2; File targetFile; BufferedImage targetImg;

How to add an ImageIcon to a JFrame?

旧城冷巷雨未停 提交于 2019-11-28 12:32:20
I'm trying to add an image to one frame but it seems it does not working. The image created by an ImageIcon from the specified file. The image file is in the seam directory the java file exist. import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class image { public static void main(String args[]) { TimeFrame frame = new TimeFrame(); } } class TimeFrame extends JFrame { //Image icon = Toolkit.getDefaultToolkit().getImage("me.jpg"); ImageIcon icon = new ImageIcon("me.jpg"); JLabel label = new JLabel(icon); public TimeFrame(){

Java Swing ImageIcon, where to put images?

房东的猫 提交于 2019-11-28 12:19:57
I'm following this tutorial for java swing games: http://zetcode.com/tutorials/javagamestutorial/movingsprites/ At this point: ImageIcon ii = new ImageIcon(this.getClass().getResource()); image = ii.getImage(); I just don't know what kind of path I have to write and where should I save my images (which directory). Would you help me please? Would you give an example? Steven In your src folder, create a folder called "images" or "files" then put the image in there. Then use this: ImageIcon(this.getClass().getResource("/images/filename.png")); If that doesn't work, try this: ImageIcon(this

Java ImageIcons and actioin listeners

送分小仙女□ 提交于 2019-11-28 10:56:34
问题 I am creating a simple game where a person clicks on an image the score increases by one. It seems simple enough, right? Here's the catch-- the images will be hidden partially behind other images! Currently, I'm using several imageIcons to set up my scene. For instance, my foreground has an image "foreground.png," my background is "background.png", and my image that is hiding between the two is "hiding.png". My first thought was to simply get the coordinates of the imageIcon hiding, add the

MouseEvents and Icon / ImageIcon

◇◆丶佛笑我妖孽 提交于 2019-11-28 09:36:14
问题 Please is possible to listening for MouseEvents from Icon / ImageIcon (in API aren't implemented any notifiers), without listening from container ( JPanel , JLabel ) or by converting events by using SwingUtilities, implements and to add XxxListener to plain vanilla Icon / ImageIcon EDIT something like as code (@pietblok), but maybe not an answer to my question, I'm not sure if create an Graphics Object, BufferedImage and paintIcon is last of property (I saw a few similair code, this is in

Changing ImageIcon to another picture with button click

☆樱花仙子☆ 提交于 2019-11-28 04:38:24
问题 So I want to replace an ImageIcon in a JLabel every time a button is pressed. I made it so the image, label, and GridBagConstraints are public. When I try to change it though nothing happens. Am I going about this the wrong way or? Thanks! package hi.low; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; import java.util.Random; import java.util.ArrayList; public class Card_panel extends JPanel implements ActionListener { private final int WIDTH =

Rendering BufferedImage in JTable cell

僤鯓⒐⒋嵵緔 提交于 2019-11-28 02:28:32
I need to display a BufferedImage in one JTable column. I overwrote JTable method @Override public Class<?> getColumnClass(int column) { if (column == 1){ return BufferedImage.class; } return super.getColumnClass(column); } But I am still obtaining String representation of the object instead of image itself.Does anyone have idea what I am missing? I'd populate the column that needs to show an image with ImageIcons and have the getColumnClass() method return Icon.class, and then render it with a JLabel that displays the Icon. In fact, I believe that the DefaultCellRenderer really is a JLabel,

Java Path ImageIcon URL .JAR

强颜欢笑 提交于 2019-11-28 01:33:18
I may have made of try, none works.. The file is: /Users/Toto/Desktop/Titi/IUT/Java/TP2/project/src/fichierPointJava/img1.png fichierPointJava is the name of the package . I launch the ant when I am situated in project which contains the build.xml Here are the codes that I tested: URL urlImage1=this.getClass().getClassLoader.getResource("/src/fichierPointJava/img1.png"); URL urlImage1=this.getClass().getClassLoader.getResource("/fichierPointJava/img1.png"); URL urlImage1=this.getClass().getClassLoader.getResource("fichierPointJava/img1.png"); URL urlImage1=this.getClass().getClassLoader

how to auto change image in java swing?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 19:38:14
问题 Hi i am creating a java desktop application where i want to show image and i want that all image should change in every 5 sec automatically i do not know how to do this here is my code public class ImageGallery extends JFrame { private ImageIcon myImage1 = new ImageIcon ("E:\\SOFTWARE\\TrainPIS\\res\\drawable\\yellow.png"); private ImageIcon myImage2 = new ImageIcon ("E:\\SOFTWARE\\TrainPIS\\res\\drawable\\d.jpg"); private ImageIcon myImage3 = new ImageIcon ("E:\\SOFTWARE\\TrainPIS\\res\

Customize JOptionPane Dialog

◇◆丶佛笑我妖孽 提交于 2019-11-27 15:15:01
I am learning java swing. The code below is a catch block which handles an IOException and shows a error message. catch(IOException e) { System.out.println("IOException"); JOptionPane.showMessageDialog(null,"File not found",null, JOptionPane.ERROR_MESSAGE); } I was thinking of declaring and customizing a JOptionPane of my own inside the catch block like the code below: JOptionPane jop=new JOptionPane(); jop.setLayout(new BorderLayout()); JLabel im=new JLabel("Java Technology Dive Log", new ImageIcon("images/gwhite.gif"),JLabel.CENTER); jop.add(im,BorderLayout.NORTH); jop.setVisible(true); But