imageicon

Fit size of an ImageIcon to a JButton [duplicate]

喜夏-厌秋 提交于 2019-12-04 05:43:27
问题 This question already has answers here : Resizing icon to fit on JButton in Java? (4 answers) Closed 3 years ago . Hi how can I fit the size of a ImageIcon to a JButton? I want to adjust the size of the ImageIcon to the size of the Button JFrame frame2 = new JFrame("Tauler Joc"); JPanel panell = new JPanel(); ImageIcon icon = new ImageIcon("king.jpg"); JButton jb= new JButton(icon); jb.setBounds(200,200,700,700); panell.add(jb); frame2.add(panell); frame2.setDefaultCloseOperation(JFrame.EXIT

Java adding ImageIcon to JLabel

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:50:35
I am trying to make a very basic game with Java and I am having trouble displaying an image on a JFrame . It has worked in the past for me and now is not, i can't see what I did wrong. I have tried printing the current working directory and changing where I get my image to match that. It is likely that the problem is not getting the image, since my (filefinder or filereader or something like that) can find it without problems, but I cannot correctly add it (the ImageIcon ) to the JLabel , or that to the JFrame . This is my code... JFrame frame = new JFrame("no image"); ImageIcon image = new

Is there a way to store data in a JButton?

穿精又带淫゛_ 提交于 2019-12-04 02:21:53
问题 My program currently adds an image to a List, which it then creates a Jbutton dynamically storing a thumbnail. Like found here. although the images are added as the user selects them. The issue I am having is that I cannot get the image to change to the thumbnail that is selected as they are not linked to the images in the list. Is there a way I can store the index number of the image in the button, so when I click it I know which image to show in the List? Or is there another more

Resizing an image in swing

ε祈祈猫儿з 提交于 2019-12-03 20:59:59
问题 I have snippet of code that I am using for the purpose of resizing an image to a curtain size (I want to change the resolution to something like 200 dpi). Basically the reason I need it is because I want to display the image that the user have picked (somewhat large) and then if the user approves I want to display the same image in a different place but using a smaller resolution. Unfortunately, if I give it a large image nothing appears on the screen. Also, if I change imageLabel.setIcon

save resized image java

隐身守侯 提交于 2019-12-03 14:25:46
How do i save a resized image to a specific folder? private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { ImgChooser ic = new ImgChooser(); ImageIcon icon = new ImageIcon(me,"id pic"); Image img1 = icon.getImage(); Image img2 = img1.getScaledInstance(105, 105, 0); icon.setImage(img2); jLabel1.setIcon(icon); } This first code is where i get the image and resize it. Then i want the resized image to be saved in another folder. Thanks in advance Use ImageIO.write(...) as others have already said (+1 to them), to add here is an example for you: public static void main(String[] args

JButton background image

限于喜欢 提交于 2019-12-03 08:20:17
Hi i am trying to implement Action listener for JButton and code look like following: ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png")); one = new JButton("",imageForOne); one.setPreferredSize( new Dimension(78, 76)); one.addActionListener(myButtonHandler); Using the above JButton it looks fine When i add specific value to button for e.g. ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png")); //Check this one = new JButton("one",imageForOne); one.setPreferredSize( new Dimension(78, 76)); one.addActionListener(myButtonHandler); It

Add a picture to a JFrame

佐手、 提交于 2019-12-02 23:56:49
问题 All I am trying to do is add a picture to a JFrame . I am really confused and don't really understand... I have looked up every possible question on this site, looked on other java stuff, such as forums. I tried my best and now I must ask guys for help. I hope the code is clean and easy to read. Thanks for the help. package zeus; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.ImageIcon; public class Main extends JFrame{ public static final int WIDTH = 800; public

Mirroring an Object in JFrame with paintComponent

笑着哭i 提交于 2019-12-02 21:26:26
问题 I created a class which is a "mirror" object. The class constructor has mirrors coordinates and direction. In this class also there is a paintComponent method. I am trying to create a mirror object with this class in my frame and automatically paint a mirror with coordinates and direction. There is the "mirror" class. Can I do this like that? import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JComponent; @SuppressWarnings("serial") class Mirror

Java getClass().getResource on a png returning Null Pointer

只愿长相守 提交于 2019-12-02 16:50:08
问题 I am not sure if I am referring to the right location with this code, the images I am trying to access are titled Flower0.png etc. They are located in the same directory as the rest of my code for this project. This class is in a src folder called hangman.ui and the .png files are located in a directory folder called Resources . Perhaps getClass().getResource is not right? This is my first time trying to put images into a GUI. Help is much appreciated! public WiltingFlowerRendererRemix

Change photo when you click a button

十年热恋 提交于 2019-12-02 16:43:21
问题 import javax.swing.Icon; import javax.swing.ImageIcon; public class Stage1 extends javax.swing.JFrame { int score = 0; int iter = 1; public Stage1() { initComponents(); setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("Stage 1"); Icon ic = new ImageIcon("a"+ iter + ".jpg"); pic.setIcon(ic); } private void submitActionPerformed(java.awt.event.ActionEvent evt) { if(answer.getText().equals("input")) { score++; iter++; answer.setText(""); String sc = Integer.toString(score); jLabel1.setText(sc);