How to highlight Icon with mouse click ?

This program will open up a JFileChooser, Select one or more than one images from your computer. It will display them as Icons.
I am trying to highlight any icon with mouseclick from the program below but I am not able to do it. Please help. Thanks in advance.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.*;
import javax.swing.border.Border;
public class IconIllustrate extends JFrame implements ActionListener, MouseListener
JLabel[] lblimage = new JLabel[10];
JPanel panAttachment = new JPanel();
JPanel panButton = new JPanel();
JButton bAdd = new JButton("Add");
Component comp = null;
Component c = null;
boolean bolVal = false;
public IconIllustrate()
// TODO Auto-generated constructor stub
panButton.add(bAdd);
bAdd.addActionListener(this);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(panAttachment, BorderLayout.CENTER);
this.getContentPane().add(panButton, BorderLayout.SOUTH);
* @param args
public static void main(String[] s)
// TODO Auto-generated method stub
IconIllustrate ii = new IconIllustrate();
ii.setLocation(300, 200);
ii.setTitle("Testing Highlight Icon");
ii.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ii.setSize(400, 300);
ii.setVisible(true);
public void actionPerformed(ActionEvent ae)
// TODO Auto-generated method stub
if(ae.getSource().equals(bAdd))
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
int answer = chooser.showOpenDialog(this);
File[] file = null;
String[] fileName = new String[10];
if(answer == JFileChooser.OPEN_DIALOG)
file = chooser.getSelectedFiles();
ImageIcon icon;
try
for(int i = 0; i < file.length; i++)
icon = new ImageIcon(file.toString());
ImageIcon thumbnailIcon = new ImageIcon(getScaledImage(icon.getImage(), 50, 40));
lblimage = new JLabel[10];
lblimage[i] = new JLabel();
lblimage[i].addMouseListener(this);
lblimage[i].setName("" + i);
lblimage[i].setBorder(BorderFactory.createEmptyBorder());
lblimage[i].setVerticalTextPosition(JLabel.BOTTOM);
lblimage[i].setHorizontalTextPosition(JLabel.CENTER);
lblimage[i].setHorizontalAlignment(JLabel.CENTER);
lblimage[i].setIcon(thumbnailIcon);
panAttachment.add(lblimage[i]);
panAttachment.revalidate();
catch(Exception ex )
ex.printStackTrace();
private Image getScaledImage(Image srcImg, int w, int h)
BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = resizedImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(srcImg, 0, 0, w, h, null);
g2.dispose();
return resizedImg;
public void mouseClicked(MouseEvent me)
// TODO Auto-generated method stub
int clickCount = me.getClickCount();
if(clickCount == 1 || clickCount == 2)
Component comp = me.getComponent();
Component c = comp.getComponentAt(me.getX(), me.getY());
// c.setPreferredSize(new Dimension(100, 100));
c.setBackground(Color.CYAN);
System.out.println("clickCount");
repaint();
this.panAttachment.revalidate();
public void mouseEntered(MouseEvent arg0)
// TODO Auto-generated method stub
public void mouseExited(MouseEvent arg0)
// TODO Auto-generated method stub
public void mousePressed(MouseEvent arg0)
// TODO Auto-generated method stub
public void mouseReleased(MouseEvent arg0)
// TODO Auto-generated method stub

Hi,
phungho2000 wrote:
Thank you for the Code. Now I am able to set the label border. I need to figure out how keep track of the last selected component so that I can reset the border.**g**
No, you have still fundamental misunderstood how listeners are working. You add a listener to a component. From this time on, this listener is watching this component. It listens if something occurs with this component therefor it is competent. If so, then it will pay attention to this. So the listener always knows the components it is in charge of. There is no need for you to "keep track of the last selected component" because the listener is doing this for you already.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.*;
public class FocusTesting extends JFrame implements FocusListener, MouseListener
  // There is no need for JLabel fields here.
  //JLabel labelA = new JLabel("Label A");
  //JLabel labelB = new JLabel("Label B");
  public FocusTesting()
    super("FocusTesting");
    JPanel paneFirst = new JPanel();
    JPanel paneSecond = new JPanel();
    paneSecond.setBackground(Color.gray);
    //use simply FlowLayout for testing this
    //paneFirst.setLayout(new BorderLayout());
    paneFirst.setBorder(BorderFactory.createBevelBorder(2));
    // pane.setBackground(Color.blue);
    JLabel labelA = new JLabel("Label A");
    // give the labelA a name only to show you, that the listener knows about the compontent it ist added to
    labelA.setName(labelA.getText());
    labelA.addMouseListener(this);
    labelA.addFocusListener(this);
    labelA.setFocusable(true);
    JLabel labelB = new JLabel("Label B");
    // give the labelB a name only to show you, that the listener knows about the compontent it ist added to
    labelB.setName(labelB.getText());
    labelB.addMouseListener(this);
    labelB.addFocusListener(this);
    labelB.setFocusable(true);
    paneFirst.add(labelA);
    paneFirst.add(labelB);
    this.getContentPane().setLayout(new GridLayout(2, 1));
    this.getContentPane().add(paneFirst);
    this.getContentPane().add(paneSecond);
  public static void main(String[] s)
    //separate the initial thread form the event dispatch thread
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        FocusTesting ft = new FocusTesting();
        ft.setLocation(300, 200);
        ft.setSize(300, 200);
        ft.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ft.setVisible(true);
  public void focusGained(FocusEvent fe)
    // TODO Auto-generated method stub
    JComponent jcomp = (JComponent)fe.getComponent();
    jcomp.setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
    System.out.println("focusGained " + jcomp.getName());
  public void focusLost(FocusEvent fe) 
    // TODO Auto-generated method stub
    JComponent jcomp = (JComponent)fe.getComponent();
    jcomp.setBorder(BorderFactory.createEmptyBorder());
    System.out.println("focusLost " + jcomp.getName());
  public void mouseClicked(MouseEvent me)
    Component comp = me.getComponent();
    comp.requestFocusInWindow();
    System.out.println("mouseClicked " + comp.getName());
  public void mouseEntered(MouseEvent arg0)
    // TODO Auto-generated method stub
  public void mouseExited(MouseEvent arg0)
    // TODO Auto-generated method stub
  public void mousePressed(MouseEvent arg0)
    // TODO Auto-generated method stub
  public void mouseReleased(MouseEvent arg0)
    // TODO Auto-generated method stub
} You also should read again the Java Tutorial about Concurrency in Swing. Especially why and how to separate the initial thread form the event dispatch thread. [http://java.sun.com/docs/books/tutorial/uiswing/concurrency/initial.html]
Also have a look on [http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html], especially [http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#focusable] for why use the MouseListener too.
And if you have understood that all, then you may think about in what way it would be much easier to use JButton's instead of JLabel's for your clickable and focusable thumbnails.
best regards
Axel

Similar Messages

  • How to highlight text with Adobe Reader XI?

    email [email protected]

    Thanks. The PDF file was made from a web site article and I guess this is the same as scanned as I cannot highlight.  The cursor changes but cannot highlight what I want.
    I was able to add text and I did this in Red and will ask the VA to read under the sections marked in Red.
    Thanks,
    Vernon Pobanz
          From: ~graffiti <[email protected]>
    To: vernon pobang <[email protected]>
    Sent: Tuesday, October 7, 2014 11:57 AM
    Subject:  How to highlight text with Adobe Reader XI?
    How to highlight text with Adobe Reader XI?
    created by ~graffiti in Adobe Reader - View the full discussionUse the highlight tool under Comment>Annotations. This will only work if the pdf isn't a scanned image. If that is the case, there is no text to highlight. Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at https://forums.adobe.com/message/6800192#6800192 Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:  To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link.  Start a new discussion in Adobe Reader by email or at Adobe Community For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • How modificate this script from mouse click to release

    how modificate this script from mouse click to release
    package
    * A Colorful Fireworks Demonstration in Actionscript 3
    *   from shinedraw.com
    import flash.events.MouseEvent;
    import flash.system.ApplicationDomain;
    import flash.events.Event;
    import flash.display.MovieClip;
    import com.shinedraw.effects.ColorfulFireworks;
    public class Document extends MovieClip{
    private var _colorfulFireworks : ColorfulFireworks;
    public function Document(){
    this.addEventListener(Event.ADDED_TO_STAGE, on_added_to_stage);
    private function on_added_to_stage(e : Event):void{
    // place the object to the stage
    _colorfulFireworks = new ColorfulFireworks();
    addChild(_colorfulFireworks);
    // add the cover to save CPU time
    var coverClass : Class = ApplicationDomain.currentDomain.getDefinition("Cover") as Class;
    var cover : MovieClip = new coverClass();
    addChild(cover);
    cover.addEventListener(MouseEvent.CLICK, on_cover_click);
    // remove the cover after click
    private function on_cover_click(e:MouseEvent):void{
    var cover:MovieClip = e.target as MovieClip;
    removeChild(cover);
    _colorfulFireworks.start();

    solved close pls

  • User Control screwed up but unable to click on icons with Mouse on OSX 10.8

    I dont know what has happened, but today user control with mouse and trackpad on my macbookpro is screwed up.
    I rebooted twice, it made no difference.
    The trackpad moves the cursor okay, but I cannot get tapping or clicking the trackpad have any effect.
    With my mouse I can access menubars, but the left and right buttons are swapped round, or it might be that the right button is acting as both left and right button.
    I then went to the System Preferences screen to try and fix the mouse preferences, but clicking on any icon with left or right button has no effect.
    I then found no icons of that type seem to work, I thought Id try and just update OSX with any updates available hoping that would fix anything that has got corrupted. But although I can get to the Appstore Update screen and there are two updates available I cannot get the updates installed. Clicking with the left button does nothing, clicking with right button changes the colour of the button slightly so the bottom half is in gray but nothing else happens.
    As there is no menu option to install the updates I thought I tried and install the updates using the keyboard but I cannot work out how to do this.
    Does this sound like a hardware or software problem
    Help Please !

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Why can I now highlight text with mouse pointer in Adobe Reader 9

    I just downloaded Adobe Reader X. I think I prefer Reader 9. I don't like being able to click in the document and have a flashing place mark (right terminology?) there. This is now happening in the Reader 9 version too, and I can copy text this way, but I don't want this. I didn't change any preferences. Can anyone help?

    Like I said, I didn't change any of the preferences, so I don't know why this happened. I think it only happened after I opened Adobe Reader X. I see no options in preferences for turning on or off the ability to highlight text with your mouse pointer, and I thought you were not supposed to be able to do this in Adobe Reader 9.

  • How can I (neatly) control mouse click events in a multi-dimensional array?

    Hello everyone!
         I have a question regarding the use of mouse clicks events in a multi-dimensional array (or a "2D" array as we refer to them in Java and C++).
    Background
         I have an array of objects each with a corresponding mouse click event. Each object is stored at a location ranging from [0][0] to [5][8] (hence a 9 x 6 grid) and has the specific column and row number associated with it as well (i.e. tile [2][4] has a row number of 2 and a column number of 4, even though it is on the third row, fifth column). Upon each mouse click, the tile that is selected is stored in a temporary array. The array is cleared if a tile is clicked that does not share a column or row value equal to, minus or plus 1 with the currently targeted tile (i.e. clicking tile [1][1] will clear the array if there aren't any tiles stored that have the row/column number
    [0][0], [0][1], [0][2],
    [1][0], [1][1], [1][2],
    [2][0], [2][1], [2][2]
    or any contiguous column/row with another tile stored in the array, meaning that the newly clicked tile only needs to be sharing a border with one of the tiles in the temp array but not necessarily with the last tile stored).
    Question
         What is a clean, tidy way of programming this in AS3? Here are a couple portions of my code (although the mouse click event isn't finished/working correctly):
      public function tileClick(e:MouseEvent):void
       var tile:Object = e.currentTarget;
       tileSelect.push(uint(tile.currentFrameLabel));
       selectArr.push(tile);
       if (tile.select.visible == false)
        tile.select.visible = true;
       else
        tile.select.visible = false;
       for (var i:uint = 0; i < selectArr.length; i++)
        if ((tile.rowN == selectArr[i].rowN - 1) ||
         (tile.rowN == selectArr[i].rowN) ||
         (tile.rowN == selectArr[i].rowN + 1))
         if ((tile.colN == selectArr[i].colN - 1) ||
         (tile.colN == selectArr[i].colN) ||
         (tile.colN == selectArr[i].colN + 1))
          trace("jackpot!" + i);
        else
         for (var ii:uint = 0; ii < 1; ii++)
          for (var iii:uint = 0; iii < selectArr.length; iii++)
           selectArr[iii].select.visible = false;
          selectArr = [];
          trace("Err!");

    Andrei1,
         So are you saying that if I, rather than assigning a uint to the column and row number for each tile, just assigned a string to each one in the form "#_#" then I could actually just assign the "adjacent" array directly to it instead of using a generic object to hold those values? In this case, my click event would simply check the indexes, one at a time, of all tiles currently stored in my "selectArr" array against the column/row string in the currently selected tile. Am I correct so far? If I am then let's say that "selectArr" is currently holding five tile coordinates (the user has clicked on five adjacent tiles thus far) and a sixth one is being evaluated now:
    Current "selectArr" values:
           1_0
           1_1, 2_1, 3_1
                  2_2
    New tile clicked:
           1_0
           1_1, 2_1, 3_1
                  2_2
                  2_3
    Coordinate search:
           1_-1
    0_0, 1_0, 2_0, 3_0
    0_1, 1_1, 2_1, 3_1, 4_1
           1_2, 2_2, 3_2
                  2_3
         Essentially what is happening here is that the new tile is checking all four coordinates/indexes belonging to each of the five tiles stored in the "selectArr" array as it tries to find a match for one of its own (which it does for the tile at coordinate 2_2). Thus the new tile at coordinate 2_3 would be marked as valid and added to the "selectArr" array as we wait for the next tile to be clicked and validated. Is this correct?

  • Problems with mouse clicks..

    Hello.
    i�m having problems with the mouse clicks in a component...
    i have events that occur when a click is given and others when 2 clicks are given, but these events occurs only once a while....it�s not always that they occur...
    can anyone help me with it?? it�s very strange...
    thanx

    How about copy and pasting your mouseClicked or mousePressed methods. Are you sure you know the difference between a click and a press?

  • How to have icons with a WM (without installing a whole DE)

    Hi!
    I was wondering if it was possible to have desktop icons with TWM/FluxBox/IceWM alone, without installing a desktop environment. As far as I know, file managers do this in DEs but then simply installing a file manager while running a WM doesn't put icons on the screen...
    Thank you in advance!

    Thank you guys! I actually searched not only through the wiki but tried to google it too. Now I feel sorry to have opened a thread that can be solved with a link from the wiki. Maybe I should have looked better... Nevertheless, thank you for the information.
    I was trying to make a lightweight system so looks like nautilus isn't for me (as Trilby said I will need to install gnome too, which is too heavy for my goals). I will however try to make it show the files that are in /user/Desktop/ for the sake of it... I don't like leaving things halfway done! Then I will maybe move on to rox and pcmanfm but one thing is for sure - I LOVE icons and it doesn't matter how lightweight a system is, for me, it is a must to have icons
    And about Tdy's responce:
    I haven't thought about these icons you said. I actually wanted that everything in /user/Desktop be showed on the desktop but I sure think that those you suggested would come in handy too. I will think about them after I have finished the main task, that is - the /user/Desktop/ thing
    Thank you again!

  • How to create Icon with transparent shape inside

    Hi All
    I would like to create a vector icon with a transparent shape inside it, like in this image below:
    So everything should be transparent except of course the dark grey area...
    How Do I do that?
    Below is a link to my AI file if you want it:
    AI File
    Thank you!

    With just the book icon selected, release clipping mask. Select both items, Minus Front.
    Is that what you did? What Illy version?
    this is what I get, green rectangle was placed behind to see the "hole."
    Mike

  • Firefox 9.0.1 with Flash player not catch keyboard event with mouse click.

    In a flash application, I need select mutil items using shite key and mouse click, it is not working. looks like firefox didn't pass the keyboard even alone with the click event. This happen on Window 7, IE and Chrome have no problem. only FF

    i have the same problem everytime i open a website with flashcontent firefox freezes and i have to kill the flash process to unfreeze the browser the only way i can see a youtube video is in html5 mode.
    Hardware
    Acer aspire 4553
    Turion X2 p520
    3gb of ddr3 ram
    Ati Mobility Radeon 4250

  • How to control timleline with mouse x coordinates

    Hi,
    Does anyone know a good tutorial on how to create a movie with a sequence of pictures and controlling the timeline frames with mouse x-coordinates?
    Regards,
    MH

    basiclly,these swfs didn't work in mailtimeline movies.some of them were created by  flash3D .
    the point is some functions what created mouseX & DisplayMovies mapping like this
    function mouseMoveH(e){
              displayrender()
    function mapping(){
         return  fun(mouseX)
    function displayrender(){
        showFrame(mapping)

  • Issues with mouse clicks/jumps after using CleanMyMac App.

    Since using this app. my hitherto slightly slow responding iMac has required multiple mouse clicks and is less/unresponsive.
    Anyone else used this software?
    As yet have not approached CleanMy Mac.
    I have reinstalled Mountain Lion (download) not clean install.
    Any suggestions? Is there a separate app for mouse that I can reload. Im guessing a minor chunk of code was deleted along with rubbish.
    Reg25x

    Uninstall CleanMyMac and do not reinstall it.
    CleanMyMac is one of a broad category of time- and money-wasters capable of causing system corruption that can only be rectified by reinstalling OS X, restoring from a backup, or completely erasing your system and rebuilding it from the ground up. Get rid of it and test your Mac for operation. If it does not perform normally, the possibility that Cleanmymac resulted in system corruption must be considered.
    The vast majority of Mac problems reported on this site are the direct result of having used garbage like that. Never install such junk on a Mac.

  • How do I open with one click all the windows that I have been minimized? When I right click on the lower bar Firefox icon, I only see the option to close all windows.

    It is used to be that I could right click on the Firefox icon on the toolbar at the bottom of the screen and I would then be given the option to open all windows. Now I only see the option to close all windows. The ability to open all windows is very useful. Have you eliminated this capability? It was a very helpful feature because I often have more than 15 windows minimized at one time. On a regular basis I like to open them all and keep only the ones that I still need. I know that it is possible to see the name of each window that is minimized by moving my cursor over the Firefox icon, but this does not provide enough information. So I have to open each window one at a time to look at it and then decide to close it or keep it - this is a frustrating, time-consuming process. Is there another way to open all the minimized windows at the same time, instead of one at a time?

    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox and the plugin-container from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.org/kb/Server+not+found
    *https://support.mozilla.org/kb/Firewalls
    You can retrieve the certificate and check details like who issued certificates and expiration dates of certificates.
    * Click the link at the bottom of the error page: "I Understand the Risks"
    Let Firefox retrieve the certificate: "Add Exception" -> "Get Certificate".
    * Click the "View..." button and inspect the certificate and check who is the issuer.
    You can see more Details like intermediate certificates that are used in the Details pane.

  • Desktop files won't open with mouse click

    I'm sure this has an obvious solution, but I can't find it.
    (I'm on a new Powerbook G4 running Tiger)
    When I try to open a folder or file on my desktop by double clicking it, nothing happens.
    However, when I click once on the folder/icon to highlight it, then hit Command + O, it opens/launches.
    I want to be able to open files with my touchpad without having to use the keys. Is there a setting for this?
    Thanks!!!!
    Powerbook G4 15"   Mac OS X (10.4.1)  

    You might want to go into the System Preferences under "Keyboard & Mouse" and check your double-click settings. Also, if I understand correctly, to click using the trackpad itself, you can select "Clicking" under the trackpad options.
    PowerBook G4 12 1.5GHz and a bag full of goodies!   Mac OS X (10.4.4)   80GB HD, 512 MB ram, 300GB Maxtor OneTouch II FireWire 400 External HD.

  • How to duplicate tabs with one click in Firefox 35 (Mac)?

    Trying to switch from Chrome to Firefox, but really missing that right-click "duplicate tab" option in Chrome--quick, easy, one-handed. Any suggestions for how to do this in Firefox 35.0? Former add-on is not compatible. Need this for Mac. Thanks.

    * Hold Ctrl and left-click or middle-click items in the history of the Back and Forward buttons to open a page from that list in a new tab<br>You can hold down the left mouse button on the Back or Forward button to open the tab history.
    * Duplicate a tab with its history by pressing the Option key and dragging the tab to a new position on the tab bar.
    *https://support.mozilla.org/kb/Keyboard+shortcuts
    *https://support.mozilla.org/kb/Mouse+shortcuts

Maybe you are looking for

  • Release strategy for Schedule lines in SD

    Hello All Can we create a release strategy for Schedule Lines in Scheduling Agreement? If Yes How? I have already maintained a release strategy for Item Level... which I want to put it for Schedule line as well.... Thanks in advance.

  • Scheduling of process chain with background job

    Hello All,               I have scheduled the process chains through background jobs. I have copied the meta chain and created seven background jobs that is from Monday till sunday. The problem is most frequently the job gets cancelled with the messa

  • "User" did not resond

    So - i, like milions of other iChat users am tired of seeing th "User (my name) did not respond" message. I have read through all the stuff (what to do to my computer - what to do to my network router). is their any new current advice on fixing the p

  • Cannot start Classic mode after 10.3.9 update

    Hi! I recently used the "Software Update" tool to update my 10.3 OS version to 10.3.9. After doing this, I found that I could no longer start Classic mode while in OSX. I did a clean install and can boot using OS 9.2.2, no problems. But I still canno

  • Alter system kill session always gives ORA-00030

    Hello Im writing a tool for oracle and one of its features requires killing user session (Im connecting with JDBC). The database Im testing on is 11.2.0.2. I find the sid and the serial# without problems, than I issue the "alter system kill session '