imageicon

Is there a way to store data in a JButton?

北城余情 提交于 2019-12-01 13:59:28
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 intelligent way? Thanks. //Create thumbnail private void createThumbnail(ImpImage image){ Algorithms a = new

Black square showing when adding a .GIF on JPanel

百般思念 提交于 2019-12-01 06:46:53
My problem is that when adding a .GIF to a JPanel, it shows this black square background for the .GIF. Result when adding on JPanel: It happens when I use this line: p2.add(loadBar); // where p2 = new JPanel(); However, when I add the same .GIF on the JFrame, the black square is not there anymore. Like this: jf.add(loadBar); // where jf = new JFrame(); Result when adding on JFrame: Part of the class code: String loadLink = "http://i.imgur.com/mHm6LYH.gif"; URL ajaxLoad = null; try { ajaxLoad = new URL(loadLink); } catch (MalformedURLException e3) { // TODO Auto-generated catch block e3

Black square showing when adding a .GIF on JPanel

孤街浪徒 提交于 2019-12-01 04:20:45
问题 My problem is that when adding a .GIF to a JPanel, it shows this black square background for the .GIF. Result when adding on JPanel: It happens when I use this line: p2.add(loadBar); // where p2 = new JPanel(); However, when I add the same .GIF on the JFrame, the black square is not there anymore. Like this: jf.add(loadBar); // where jf = new JFrame(); Result when adding on JFrame: Part of the class code: String loadLink = "http://i.imgur.com/mHm6LYH.gif"; URL ajaxLoad = null; try { ajaxLoad

I took this code straight out of 'Java all in one for Dummies' …why doesn't it work?

浪尽此生 提交于 2019-11-30 23:17:34
import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @SuppressWarnings("serial") public class Picture extends JFrame{ public static void main(String[] args){ new Picture(); } public Picture(){ this.setTitle("Picture"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); ImageIcon pic = new ImageIcon("TestImage.jpg"); p.add(new JLabel(pic)); this.add(p); this.pack(); this.setVisible(true); System.out.println(pic); } } This code as it is just displays a collapsed frame. I would expect that the pack(); method call

Resizing an image in swing

泄露秘密 提交于 2019-11-30 21:55:45
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(newIcon); to imageLabel.setIcon(icon); I get the image to display but not in the correct resolution that's

Auto-resizing JButton Icon

扶醉桌前 提交于 2019-11-30 19:25:23
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); setIcon (resizeIcon(icon,60,60)); } resizeIcon being a personal function, that takes an Icon, a width

I took this code straight out of 'Java all in one for Dummies' …why doesn't it work?

心不动则不痛 提交于 2019-11-30 17:26:34
问题 import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @SuppressWarnings("serial") public class Picture extends JFrame{ public static void main(String[] args){ new Picture(); } public Picture(){ this.setTitle("Picture"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); ImageIcon pic = new ImageIcon("TestImage.jpg"); p.add(new JLabel(pic)); this.add(p); this.pack(); this.setVisible(true); System.out.println

Java - Convert Image to Icon/ImageIcon?

六月ゝ 毕业季﹏ 提交于 2019-11-30 14:42:00
问题 I have an Image object that I would like to convert to an Icon or ImageIcon to add to a JTextPane. How would I go about doing this? (this is in JAVA) clarification: my "Image" is an instance of the Image Object, not a File. 回答1: What's wrong with new ImageIcon(Image)? Image img = ... ImageIcon icon = new ImageIcon(img); 回答2: Add the image to your JTextPane document: Image image = ImageIO.read(new File("myImage.jpg")); StyleContext context = new StyleContext(); StyledDocument document = new

Java - Convert Image to Icon/ImageIcon?

我们两清 提交于 2019-11-30 11:23:49
I have an Image object that I would like to convert to an Icon or ImageIcon to add to a JTextPane. How would I go about doing this? (this is in JAVA) clarification: my "Image" is an instance of the Image Object, not a File. What's wrong with new ImageIcon(Image) ? Image img = ... ImageIcon icon = new ImageIcon(img); Add the image to your JTextPane document: Image image = ImageIO.read(new File("myImage.jpg")); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new

ImageIcon Help + Close a JOptionPane

烈酒焚心 提交于 2019-11-30 06:07:24
问题 I'm trying to get the PayPal logo come up when you click the 'rightbutton' is clicked. Unfortunately, all that shows is the default Java logo with the cup of coffee and a pen. Also, how can I make it so once you click "OK" or "Cancel" it closes the JOptionPane, currently, when you click "OK" nothing happens, it keeps giving you the "OK" / "Cancel" option. rightbutton = new JButton("Right."); add(rightbutton); rightbutton.addActionListener( new ActionListener(){ public void actionPerformed