JLabel Icon from online image?
I am writing a program (purely for curiosity-sake) that searches the automotive section of a popular online classifieds website, retrieves the 20 latest ad posts (the 20 newest cars posted), and displays the title ("1969 Mustang, great shape! Must sell!", etc.), price, description, and post time/date in labels in my program (using Swing). This all works fine so far, but one feature I would like to implement is causing me some grief. Each online posting has a thumbnail image which I would like to retrieve and display in my program. I would like to use a JLabel, then set the "icon" property to reference the online image. I don't wish to have hundreds of thumbnails caches in programs' project folder, so is there a way to set the label's icon property to not only an external image, but an online one? I am using NetBeans 6.0.1 and JDK1.6.0_03. In NetBeans, using the Properties window on the right, the "icon" property allows me to choose an external, but local, image -- this doesn't help much. All online thumbnails are the same size (64x48), and my label is the same size (it will be strictly an image displayer, no text). Any help greatly appreciated!
ImageIO could load from the URL of the image of your interest.
Similar Messages
-
How do you make an icon from an image
Used to be if you selected "Get Info" you could get an icon from the info window. Now all I get is this.
Yup - apparently the OS does not make actual thumbnails anymore for files; instead, it uses something like Preview to generate them on the fly. This means that when you do a Get Info on them, the icon shown in the upper left is a generic one.
A solution -
Lower down in the Get Info window is a preview of the image. Double-click that, and it will open in Preview. Press Command-A (Select All) then Command-C (Copy). This will place the image on the Clipboard.
Switch to the Get Info window for the file or folder you want to place the image onto as an icon, click the generic one in the upper left to select it, press Command-V (Paste). -
Cannot remove Disk Icons from Disk Images or External Drives from Desktop
After years with PPCs, I just upgraded to an Intel Mac. I am now running into a funny problem. The majority of the time (although occasionally it works as it should), I am unable to eject disks. These include disk images from my internal hard drive, external hard drives, and disk images from external hard drives.
I do not get the “Cannot eject this disk because it is in use” error that happens when something is trying to access a file on the disk; instead, nothing happens. I’ve tried ejecting by dragging the icon to the dock, hitting the eject icon in finder, right-clicking and ejecting from there, and even using a terminal-based script that I found on the WEB. None of these do anything- no errors, but the icon hangs about as if nothing happened.
Occasionally I cannot log off at all (I just get the SBBOD); here I have to do a hard reboot. Sometimes I can log off properly. Either way, all seems to be fine when I log back in.
I’ve run Applejack multiple times.
Any suggestions would be most appreciated! Thank you.
OS 10.5.6
2.8 GHz Intel Core Duo iMac with 2 GB factory RAMThe linked macfixitforums topic is over seven years old and isn't applicable. Follow nerowolfe's suggestions. Once you sort things out, see these:
Switching from Windows to Mac OS X,
Basic Tutorials on using a Mac,
MacFixIt Tutorials,
MacTips, and
Switching to the Mac: The Missing Manual, Leopard Edition.
Additionally, *Texas Mac Man* recommends:
Quick Assist.
Welcome to the Switch To A Mac Guides,
Take Control E-books, and
A guide for switching to a Mac. -
HT2493 How do create my own icon from an image
I have an application I developed - now I want to add an icon. I know how to copy and paste in an image. I would like a real .icns file. How do I make one. Didn't Mac OS used to have a utility?
Eventually found my answer at
http://stackoverflow.com/questions/11660736/xcode-4-4-removed-icon-composer-in-d eveloper-tools
Spotlight didn't find iconutil but it did come up when I did "which iconutil" in Terminal, and "man iconutil" gave me the info.
After that I wrote my own Tcl routine to create the plethora of icon images from a single image and merge them. -
JLabel (icon Image) without picture?
I am make applet containing JLabel (Icon Image). When I run this applet from server and used image-file "middle.gif" (from tutorial) - there was all Ok. After this I changed color of image on MS Photo Editor and now I get JLabel without icon and there is no errors. I don't understand what happens? Anybody know what is it?
Of course. In directory "Images" I have follow files:
green.gif
middle.gif
red.gif
Files green.gif and red.gif are middle.gif but pictures on them have respective colors. This colors I get using MS Photo Editor.
import javax.swing.*;
import java.awt.*;
import java.net.*;
public class tLabImage extends JApplet{
public void init () {
JFrame f=new JFrame();
URL url=null;
try {
// url=new URL("http://10.1.1.6/Images/middle-1.gif");
url=new URL("http://10.1.1.6/Images/green.gif");
catch (MalformedURLException e) {System.out.println (e.getMessage());}
Image image=getImage(url);
ImageIcon icon=new ImageIcon(image);
JLabel l=new JLabel ("text", icon, JLabel.LEFT);
f.setLocation(200,300);
f.getContentPane().setLayout(new GridLayout(0,2));
f.getContentPane().add(l);
f.pack();
f.setVisible(true);
When I run this programm I get JLabel without icon (only text). Why? Who can answer? -
Set a file icon from image file of same name
I have a folder of files and I have another folder of images that have the same names as the files. What I would like to do is apply an icon of each image to it's corresponding file. Is this possible? Any help would be greatly appreciated.
IanIanWfsdafeqry rasrbd wrote:
I have a folder of files and I have another folder of images that have the same names as the files. What I would like to do is apply an icon of each image to it's corresponding file. Is this possible? Any help would be greatly appreciated.
That reminds me of the question asked by Fierabras in this thread.
If both of your folders contain exactly the same number of files, and if the names of the files are the same in both folders (except the name extension of course), then the following script should do what you are asking for, though admittedly not in the background.
(The script seems to work flawlessly on my MacBook Pro under Mac OS X 10.8.)
tell application "Finder"
set folder1 to folder POSIX file "/POSIX/path/to/folder/of/images"
-- for example: "/Users/me/Desktop/My images"
set folder2 to folder POSIX file "/POSIX/path/to/folder/of/files"
-- for example: "/Users/me/Desktop/My files"
set N to (count folder1)
if not (count folder2) = N then return
set theImages to files of folder1
set theFiles to files of folder2
tell application "Image Events" to launch
repeat with k from 1 to N
set thisImageFile to item k of theImages
tell application "Image Events"
set theImage to open thisImageFile as alias
save theImage with icon
close theImage
end tell
tell application "Finder"
activate
set infoWindow1 to open information window of thisImageFile
tell application "System Events"
keystroke tab
keystroke "c" using command down
keystroke "x" using command down -- optional
end tell
close infoWindow1
set infoWindow2 to open information window of item k of theFiles
tell application "System Events"
keystroke tab
keystroke "v" using command down
end tell
close infoWindow2
end tell
end repeat
tell application "Image Events" to quit
end tell
Message was edited by: Pierre L. (“count folder” instead of “count files of folder”) -
How do I change the image used on an movie project icon?
iMovie seems to select an image at random from the images I imported.Not sure I understand how to use what you have posted. Here's what my init() looks like:
public void init()
setLayout(new BorderLayout());
p=new Panel();
p.setLayout(new GridLayout(1,1));
callnowButtonURL = getURL(callnowButtonFilename);
if (callnowButtonURL != null)
callIcon = new ImageIcon(callnowButtonURL,"call");
endcallButtonURL = getURL(endcallButtonFilename);
if (endcallButtonURL != null)
endIcon = new ImageIcon(endcallButtonURL);
b=new JButton(callIcon);
b.setBorder(new EmptyBorder(0,0,0,0));
b.setBorderPainted(false);
b.addActionListener(this);
p.add(b);
add(p,"Center");
Now the ActionListener is basically:
public void actionPerformed(ActionEvent e)
if (mybool == false)
<Perform actions here set mybool to true>
Change JButton b to use EndIcon
else
<Perform actions here set mybool to false>
Change JButton b to use CallIcon
Can you clarify how to perform the action I require? You can have a couple of Dukes if you can help me sort this out. -
How do you remove face tagging icon from images. I cannot get them off some images.
How do you remove face tagging icon from images. I cannot get them off! This is for adobe photoshop elements 6. Thanks
The links below have instructions for deleting photos.
iOS and iPod: Syncing photos using iTunes
http://support.apple.com/kb/HT4236
iPad Tip: How to Delete Photos from Your iPad in the Photos App
http://ipadacademy.com/2011/08/ipad-tip-how-to-delete-photos-from-your-ipad-in-t he-photos-app
Another Way to Quickly Delete Photos from Your iPad (Mac Only)
http://ipadacademy.com/2011/09/another-way-to-quickly-delete-photos-from-your-ip ad-mac-only
How to Delete Photos from iPad
http://www.wondershare.com/apple-idevice/how-to-delete-photos-from-ipad.html
How to: Batch Delete Photos on the iPad
http://www.lifeisaprayer.com/blog/2010/how-batch-delete-photos-ipad
(With iOS 5.1, use 2 fingers)
How to Delete Photos from iCloud’s Photo Stream
http://www.cultofmac.com/124235/how-to-delete-photos-from-iclouds-photo-stream/
Cheers, Tom -
Drag and drop icons from onside of the split pane to the other side.
Hello All,
I am tring to write a program where i can drag and drop icons from the left side of the split pane to the right side. I have to draw a network on the right side of the split pane from the icons provided on the left side. Putting the icons on the labels donot work as i would like to drag multiple icons from the left side and drop them on the right side. CAn anyone please help me with this.
Thanks in advance
smithaThe other option besides the drag_n_drop support
http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.htmlis to make up something on your own. You could use a glasspane (see JRootPane api for overview) as mentioned in the tutorial.
Here's another variation using an OverlayLayout. One advantage of this approach is that you can localize the overlay component and avoid some work.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
public class DragRx extends JComponent {
JPanel rightComponent;
BufferedImage image;
Point loc = new Point();
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if(image != null)
g2.drawImage(image, loc.x, loc.y, this);
public void setImage(BufferedImage image) {
this.image = image;
repaint();
public void moveImage(int x, int y) {
loc.setLocation(x, y);
repaint();
public void dropImage(Point p) {
int w = image.getWidth();
int h = image.getHeight();
p = SwingUtilities.convertPoint(this, p, rightComponent);
JLabel label = new JLabel(new ImageIcon(image));
rightComponent.add(label);
label.setBounds(p.x, p.y, w, h);
setImage(null);
private JPanel getContent(BufferedImage[] images) {
JSplitPane splitPane = new JSplitPane();
splitPane.setLeftComponent(getLeftComponent(images));
splitPane.setRightComponent(getRightComponent());
splitPane.setResizeWeight(0.5);
splitPane.setDividerLocation(225);
JPanel panel = new JPanel();
OverlayLayout overlay = new OverlayLayout(panel);
panel.setLayout(overlay);
panel.add(this);
panel.add(splitPane);
return panel;
private JPanel getLeftComponent(BufferedImage[] images) {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
for(int j = 0; j < images.length; j++) {
gbc.gridwidth = (j%2 == 0) ? GridBagConstraints.RELATIVE
: GridBagConstraints.REMAINDER;
panel.add(new JLabel(new ImageIcon(images[j])), gbc);
CopyDragHandler handler = new CopyDragHandler(panel, this);
panel.addMouseListener(handler);
panel.addMouseMotionListener(handler);
return panel;
private JPanel getRightComponent() {
rightComponent = new JPanel(null);
MouseInputAdapter mia = new MouseInputAdapter() {
Component selectedComponent;
Point offset = new Point();
boolean dragging = false;
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
for(Component c : rightComponent.getComponents()) {
Rectangle r = c.getBounds();
if(r.contains(p)) {
selectedComponent = c;
offset.x = p.x - r.x;
offset.y = p.y - r.y;
dragging = true;
break;
public void mouseReleased(MouseEvent e) {
dragging = false;
public void mouseDragged(MouseEvent e) {
if(dragging) {
int x = e.getX() - offset.x;
int y = e.getY() - offset.y;
selectedComponent.setLocation(x,y);
rightComponent.addMouseListener(mia);
rightComponent.addMouseMotionListener(mia);
return rightComponent;
public static void main(String[] args) throws IOException {
String[] ids = { "-c---", "--g--", "---h-", "----t" };
BufferedImage[] images = new BufferedImage[ids.length];
for(int j = 0; j < images.length; j++) {
String path = "images/geek/geek" + ids[j] + ".gif";
images[j] = ImageIO.read(new File(path));
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new DragRx().getContent(images));
f.setSize(500,400);
f.setLocation(200,200);
f.setVisible(true);
class CopyDragHandler extends MouseInputAdapter {
JComponent source;
DragRx target;
JLabel selectedLabel;
Point start;
Point offset = new Point();
boolean dragging = false;
final int MIN_DIST = 5;
public CopyDragHandler(JComponent c, DragRx dr) {
source = c;
target = dr;
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
Component[] c = source.getComponents();
for(int j = 0; j < c.length; j++) {
Rectangle r = c[j].getBounds();
if(r.contains(p) && c[j] instanceof JLabel) {
offset.x = p.x - r.x;
offset.y = p.y - r.y;
start = p;
selectedLabel = (JLabel)c[j];
break;
public void mouseReleased(MouseEvent e) {
if(dragging && selectedLabel != null) {
int x = e.getX() - offset.x;
int y = e.getY() - offset.y;
target.dropImage(new Point(x,y));
selectedLabel = null;
dragging = false;
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
if(!dragging && selectedLabel != null
&& p.distance(start) > MIN_DIST) {
dragging = true;
copyAndSend();
if(dragging) {
int x = p.x - offset.x;
int y = p.y - offset.y;
target.moveImage(x, y);
private void copyAndSend() {
ImageIcon icon = (ImageIcon)selectedLabel.getIcon();
BufferedImage image = copy((BufferedImage)icon.getImage());
target.setImage(image);
private BufferedImage copy(BufferedImage src) {
int w = src.getWidth();
int h = src.getHeight();
BufferedImage dst =
source.getGraphicsConfiguration().createCompatibleImage(w,h);
Graphics2D g2 = dst.createGraphics();
g2.drawImage(src,0,0,source);
g2.dispose();
return dst;
}geek images from
http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html -
Hello,
i am trying to load ALL imagefiles from my jar file. i do the following:
Class clazz = Class.forName("com.xxx.IconSelectionDialog");
String me = clazz.getName().replace(".", "/") + ".class";
dirURL = clazz.getClassLoader().getResource(me);
if (dirURL.getProtocol().equals("jar")) {
String jarPath = dirURL.getPath().substring(6, dirURL.getPath().indexOf("!")); //strip out only the JAR file
JarFile jar = new JarFile(jarPath );
Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
while (entries.hasMoreElements()) {
JarEntry nextEntry = entries.nextElement();
String jarEntryName = nextEntry.getName();
this works fine with my debug local jws installation. when i try to run it online starting i get an error:
java.io.FileNotFoundException: xentis.jar (Das System kann die angegebene Datei nicht finden)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.jar.JarFile.<init>(JarFile.java:133)
at java.util.jar.JarFile.<init>(JarFile.java:70)
how can i load ALL icons from a jar (without knowing the filename) ?
is there a generic way to iterate over all entries of a jarfile ?
thank you
michaelLook at "Loading Images Using getResource" on this page
http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html
It should provide some ideas. -
Hi all,
I've got my application that loads icons from a relative path, such as "img/tree/menu.png". While running outside the jar it works fine, but when I create a jar of my filesystem I cannot load the icon (i.e., it is not found). The jar of course contains the icons and the relative path.
Anybody has a clue about?
Thanks,
LucaI am loading the images for my application. For my application in development phase - I am putting the image in the source folder as well as in the jar file.
Here is the code I am using
try
URL url = this.getClass().getClassLoader().getResource(imageName);
if (url == null)
url = new File(imageName).toURL();
JLabel logo = new JLabel(new ImageIcon(url));image name is the name of the image say "xyz.gif"
In the jar file just include the image files and it should work fine. -
Filing or removing .dmg icons from the desktop
I have never known what the proper action is, after downloading apps (new versions of iTunes, for example), to remove the install .dmg extension icons from my desktop. Can they be trashed? Do I drag them to the HD? What?
Hello and Welcome to Apple Discussions.
Personally I file them in a Software Downloads folder so I know where to find them if I wish to use the software on another Mac or run the uninstaller.
Once the application has been copied to the Applications ƒ or the Installer run, you can then eject the disk image and then you are at liberty to either file or trash the .dmg.
I would say definitely keep them if there is an uninstaller but otherwise by the time you come to look at them again there is probably a newer version online so it's wasting hard disk space.
cheers
mrtotes -
I am running a MYSQL query and assigning the values to Jlabels. Like this:
jLabel2.setText ( nameVal );I want to be able to assign the icons of the jLabels as well. Is this possible?Same result. Here is the whole thing right from the tutorials:
//package components;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;
* LabelDemo.java needs one other file:
* images/middle.gif
public class LabelDemo extends JPanel {
public LabelDemo() {
super(new GridLayout(3,1)); //3 rows, 1 column
JLabel label1, label2, label3;
ImageIcon icon = createImageIcon("http://duke.kenai.com/iconSized/duke4.gif",
"a pretty but meaningless splat");
//Create the first label.
label1 = new JLabel("Image and Text",
icon,
JLabel.CENTER);
//Set the position of its text, relative to its icon:
label1.setVerticalTextPosition(JLabel.BOTTOM);
label1.setHorizontalTextPosition(JLabel.CENTER);
//Create the other labels.
label2 = new JLabel("Text-Only Label");
label3 = new JLabel(icon);
//Create tool tips, for the heck of it.
label1.setToolTipText("A label containing both image and text");
label2.setToolTipText("A label containing only text");
label3.setToolTipText("A label containing only an image");
//Add the labels.
add(label1);
add(label2);
add(label3);
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String URL,
String description) {
java.net.URL imgURL = LabelDemo.class.getResource(URL);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + URL);
return null;
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("LabelDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frame.add(new LabelDemo());
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
} -
MY envy 5330e has stopped printing anything from online sources.
MY envy 5330e has stopped printing anything from online sources but will print from on board documents or pictures.
Hey @youngfmly,
Because your HP ENVY 5530 e-All-in-One Printer is producing blank prints from three computers when printing from the the internet I'm wondering if there may actually be a hardware ink system issue occuring. I understand that this may sound odd as everything else appears to print fine. However, when printing from your computers colour ink is used to enrich the black ink when printing in certain programs. Primarily when the computer 'sends' the print job to the printer as an image file. Therefore, just to ensure that your printers ink system is functioning properly, I am going to have you print a standalone Print Quality Report.
How to Print the Quality Report:
Load plain white paper in the paper tray.
On the printer control panel, touch the Settings icon (), and then touch Tools. The Tools Menu displays.
Touch Print Quality Report. The printer prints the test page.
If this report prints perfectly: Than the issue that you're experiencing is not related to the printer. Rather, there is likely a setting that still needs to be checked under Google Chrome. If your modem/router was causing this issue all prints would be affected.
If this report prints with quality defects or missing colours: Than the Google Chrome printing issue that you're experiencing is being caused by your printer. To resolve this print system issue can I please have you click here. Once the support document opens please run through Solution six, Solution seven, and Solution eight. This includes any sub-steps under the listed Solutions.
Please let me know the result of printing this standalone Quality Report. I look forward to hearing from you!
X-23
I work on behalf of HP
Please click "Accept as Solution" if you feel my post solved your issue, it will help others find the solution.
Click the "Kudos, Thumbs Up" on the right to say "Thanks" for helping! -
When I drag and drop a website icon from the Forefox address bar to the desk top, the short cut is created but the icon that appears is the firefox Icon. I want to disply the icon from the website that the short cut refers to. I have checked all I can think of in my computer to no avail.
You have to assign the favicon yourself to the desktop shortcut (right-click the shortcut: Properties) after you have dragged the link to the desktop.
You can usually find the favicon in Tools >Page Info > Media and save the icon there.
Otherwise use the main domain of the website and add favicon.ico (e.g. mozilla.com/favicon.ico ) to display the favicon in a tab and save that image to a folder.
Maybe you are looking for
-
Exporting book to Digital Editions
Hi, I'm having quite a lot of problems in exporting a book I've created to Digital Editions and I'm sure there must be others in my situations also. The books exports fine to pdf and is fully functional.As soon as I export to DE, all pages exported a
-
Embedded Fonts on Dynamic Label Component
I am working on a project that calls for multiple label components to be dynamically rendered based on a selected comboBox selectedItem. The comboBox is a choice of fonts available to the user - all of which are embedded fonts. For some reason, the f
-
I don't know how this happened. Everything was fine last night. Is there something I need to check in View?
-
How to delete wifi access point on E7 - mails won'...
I have E7 with symbian anna. A while ago I had to restart my home wifi (due to storm) and during that process a new wifi access point (wlan(01) was created on my phone. After that - as far as I have now understood - my phone stopped syncronising gmai
-
Loading Tree Node/Leaf causing numerous errors
I am loading a tree with UNSPSC codes using an application engine program with code borrowed from a delivered app engine program. The code loads most of the codes, however I receive numerous errors as follows: Node not Found (92,3209) - I get this a