Problem with findComponentAt highlighting wrong JLabel

I've got a small 6 by 7 grid of jlabels that I would like to turn red if clicked on. In the japplet shown below, this works, sort of: it turns the label to its left red but not the label under the mouse. Any ideas on what I'm doing wrong? Thanks!
MyApplet.java
import javax.swing.JApplet;
public class MyApplet extends JApplet
    MyPane2 pane = new MyPane2();
    public void init()
        getContentPane().add(pane);
}MyPane2.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyPane2 extends JPanel implements MouseListener
    private static final int MAX_ROW = 6;
    private static final int MAX_COL = 7;
    private String whiteDot = ".\\petes\\brief3\\whiteDot.jpg";
    private String redDot = ".\\petes\\brief3\\redDot.jpg";
    private JLabel[][] myLabelGrid;
    private JPanel gridPane = new JPanel();
    public MyPane2()
        super();
        add(createLabelGridPane());
    private JPanel createLabelGridPane()
        gridPane = new JPanel();
        GridLayout myGridLO = new GridLayout(MAX_ROW, MAX_COL);
        myGridLO.setHgap(5);
        myGridLO.setVgap(5);
        gridPane.setLayout(myGridLO);
        gridPane.addMouseListener(this);
        myLabelGrid = new JLabel[MAX_COL][MAX_ROW];
        for (int row = 0; row < MAX_ROW; row++)
            for (int col = 0; col < MAX_COL; col++)
                //myLabelGrid[col][row] = new JLabel(new ImageIcon(whiteDot));
                myLabelGrid[col][row] = new JLabel("W");
                gridPane.add(myLabelGrid[col][row]);
        return gridPane;
    public void mouseClicked(MouseEvent me)
        JPanel myPanel = (JPanel)me.getSource();
        System.out.println(findComponentAt(me.getX(), me.getY()));
        Component myComponent = findComponentAt(me.getX(), me.getY());
        if (myComponent instanceof JLabel)
            //((JLabel)myComponent).setIcon(new ImageIcon(redDot));
            ((JLabel)myComponent).setText("R");
        repaint();
    public void mouseEntered(MouseEvent arg0){}
    public void mouseExited(MouseEvent arg0){}
    public void mousePressed(MouseEvent arg0){}
    public void mouseReleased(MouseEvent arg0){}
}[edited to use a label with "W" or "R" rather than images]
Message was edited by:
petes1234

//  <applet code="FindComponentApplet" width="400" height="400"></applet>
//      No html file necessary, just type
//  appletviewer FindComponentApplet.java
//      at the prompt and press enter.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FindComponentApplet extends JApplet
    public void init()
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(new FindComponentPane());
class FindComponentPane extends JPanel implements MouseListener
    private static final int MAX_ROW = 6;
    private static final int MAX_COL = 7;
    Component lastSelected;
    public FindComponentPane()
        super(new BorderLayout());
        add(createLabelGridPane());
    private JPanel createLabelGridPane()
        JPanel gridPane = new JPanel(new GridLayout(MAX_ROW, MAX_COL, 5, 5));
        gridPane.addMouseListener(this);
        JLabel[][] myLabelGrid = new JLabel[MAX_COL][MAX_ROW];
        for (int row = 0; row < MAX_ROW; row++)
            for (int col = 0; col < MAX_COL; col++)
                JLabel label = new JLabel("W", JLabel.CENTER);
                label.setBorder(BorderFactory.createEtchedBorder());
                myLabelGrid[col][row] = label;
                gridPane.add(myLabelGrid[col][row]);
        return gridPane;
    public void mouseClicked(MouseEvent me)
        JPanel panel = (JPanel)me.getSource();
        Component component = panel.findComponentAt(me.getX(), me.getY());
        System.out.println(component.getClass().getName());
        if (component instanceof JLabel)
            if(lastSelected != null)
                ((JLabel)lastSelected).setForeground(Color.black);
            ((JLabel)component).setForeground(Color.red);
            // Since there are gaps among the labels we need this in here.
            lastSelected = component;
        repaint();
    public void mouseEntered(MouseEvent arg0){}
    public void mouseExited(MouseEvent arg0){}
    public void mousePressed(MouseEvent arg0){}
    public void mouseReleased(MouseEvent arg0){}
}

Similar Messages

  • I have upgraded Apple Aperture from version 2 to version 3 and I'm having a problem with the "Highlights and Shadows" adjustment. According to the user's manual, I should have access to an advanced disclosure triangle which would allow me to adjust mid co

    I have upgraded Apple Aperture from version 2 to version 3 and I'm having a problem with the "Highlights and Shadows" adjustment. According to the user's manual, I should have access to an advanced disclosure triangle which would allow me to adjust mid contrast, colour, radius, high tonal width and low tonal width.
    If anyone has any suggestions as to how to access this advanced section, I'd be most grateful.

    Hi David-
    The advanced adjustments in the Highlights & Shadows tool were combined into the "Mid Contrast" slider in Aperture 3.3 and later. If you have any images in your library that were processed in a version of Aperture before 3.3, there will be an Upgrade button in the Highlights & Shadows tool in the upper right, and the controls you asked about under the Advanced section. Clicking the Upgrade button will re-render the photo using the new version of Highlights & Shadows, and the Advanced section will be replaced with the new Mid Contrast slider. With the new version from 3.3 you probably don't need the Advanced slider, but if you want to use the older version you can download it from this page:
    http://www.apertureexpert.com/tips/2012/6/12/reclaim-the-legacy-highlights-shado ws-adjustment-in-aperture.html

  • Problems with using highlighting feature in iBooks after updating to ios8. Please help.

    Having problems with highlighting feature in iBooks after updating ios8 to my iPad. Please help!

    I Too am having problems with iBooks highlighting the entire chapter if I touch the right edge of a page.  It overrides my previous highlighting making my studying useles. It's terribly frustrating! iOS 8 has been a big,big problem. Apple has to fix this.  There should be a way to undo it.  It's a terrible mess.

  • Problems with Saved Watermarks - Wrong Font Size

    Hi,
    I am having problems with "Saved" Watermarks, as when I selected them they have the wrong font size.
    I created a Watermark (Draft) to be placed on the lower right
    corner of a PDF, using font Arial-10. This watermark has been save using the "Save Settings..." in Watermarks.
    When I add this this "saved" watermark to a new PDF, the font size is wrong
    (much much bigger), even though the Add Watermark windows reports Arial-10. Only by a selecting a different font size and changing it back to the saved font size (10) I get the correct Font Size in the PDF.
    I had a similar problem with the placement, but managed to solve that by setting the Preference>User&Guide to the used Unit (Page&Ruler = centimeters). But for the font size I can't find anything in the preference.
    Any Help or Suggestions ?

    Hi,
    Sorry forgot to add, I am using
    Acrobat Professional 8.1.2 on Windows XP Prof.
    Cheers
    Johannes

  • Hardware ID's for problem with dv7t-3300 wrong drivers?

    I saw the message regarding the other person with problems with his video drivers so here is a screen shot of the hardware id's for my display adapter:

    Hi,
    Please try the following driver:
       http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?softwareitem=ob-100095-3&cc=us&dlc=en&lc=en...
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • OS X Lion Server display problem with menu highlighting and button icons

    I have attached  Grab capture of my screen showing the problems with the window top bars and button icons. This happened after a routine security update.
    Does anyone have an idea how to fix this?
    Thanks
    George Harrison

    I have/had the same problem. Comparible setup running Lion Server GM. The natd service fires off the InternetSharing service from the prefspane instead of the regular natd service. This is verifiable by entries in the system log as well as the lack of the natd process running. Below are my findings from research/experimentation; please understand that this is what I have done to get it working, it is DEFINITELY not best practices and I'm sure not supported by Apple. I'm just conveying what I think is happening and how I dealt with it.
    Natd - Executing the binary referenced in the launchctl job directly launches the InternetSharing service on Lion server. This does NOT act this way in SL server, where it works as expected. Replacing the Lion binaries with The SL ones results in natd working as expected: nat_start and nat_stop in /usr/libexec. In short, if you replace the Lion binaries with the ones from SL, it-s a drop-in fix. Natd isn't your only problem though...
    Dns/named - It appears that Apple has limited named to binding on the loopback adapter only by default on Lion. Adding a listen-on clause to named.conf with the appropriate bindings will fix this. I'm assuming you're running natd, named and dhcpd on the same box...
    Dhcpd - Works fine. It appears broken only because the InternetSharing service is replacing natd (why?!?) and it has a built-in dhcpd server (dumbed down 192.168.2.0 subnet). Once you fix natd, this runs as expected.
    Firewall/ipfw - Gotta have this running so that natd will do translation. Remember to open the dhcp ports to allow the clients to get leases...
    I hope this helps, I'm sticking with SL until these issues are worked out...

  • Problem with songs in wrong folder

    Hello,
    Please bear with me. I am not very good with the technical aspects of computers and with iTunes. I bought an iPhone 3GS (8GB) last week. I tried to sync it today. The apps that I had d/l from the app store on iTunes tranferred fine into the iPhone but the music and podcasts did not. I also had taken the micro SD card with a few songs in it and copied them into my PC. I then turned on itunes and noticed there were exclamation points next to the songs I transferred from the micro SD card. Long story short I tried to get the exclamation points off, I somehow moved ALL my songs from the files they were in to another one on my PC and now NONE of the songs I have in my library will play, they all have ! when I click on them, they all say to locate them and then a box pops up with the folders on my desktop. I also don't want to sync all the songs I have onto the iPhone and I know I can make playlists and then pick and choose from there. But I cna't make any playlists since all the songs are in another folder, when I highlight them in iTunes to make a playlist it won't do it.
    I just want all my songs to play without any hassle and be able to transfer over to my iPhone. Can someone please help me. thank you
    Mary

    +I also had taken the micro SD card with a few songs in it and copied them into my PC. I then turned on itunes and noticed there were exclamation points next to the songs I transferred from the micro SD card.+
    This happens a lot. iTunes was looking for them to still be on the micro SD card, but it was gone from the PC.
    The fix is to go to itunes preferences > advanced tab. Put a checkbox in "Copy files to itunes Media folder when adding...."
    Transfer the files again, so they will get copied to your PC's hard drive and not stay on the micro SD card.
    On to the 2nd problem, moving files around in Windows Explorer. iTunes will lose track of them, as you discovered. So then you changed the itunes media folder to the new location? That's great, except that only affects FUTURE additions.
    Can you put them back in the original place? Undo the rename in WIndows Explorer, in other words.

  • Problem with HTML in a JLabel

    Is it possible to use styles when using HTML in a JLabel?
    Example:
    <html><hr style="height: 1px; color: black;"></html>Doesn't work correctly as this should give a solid 1px high hr, but doesn't. Instead it gives a black hr with a white shade...
    The JLabel it is used in is not customized in any way.

    I too am interested in getting color on an HR to work. Can you summarize what you have done to date? Sample code?
    Note: An easy way to correct it in a Nonframe instance of html is to subclass HTMLEditor to implement your own ViewFactory and own HRuleView which checks the attribute tag color for the color. I've got this to work, but frames don't work since you can call FrameView (not public) and thus have to use the super class - which then by-passes the ViewFactory from then on.
    So a NON-FRAME Solution to give HR color is... Anybody have a better global solution?
    Here is the one line fix to HRuleView .setProperties. So if you subclass HRuleView specifically to do
    public class MyHTMLEditorKit extends HTMLEditorKit { // StyledEditorKit
        private static final ViewFactory defaultFactory = new MyHTMLFactory();
        public static class MyHTMLFactory extends HTMLFactory {//implements ViewFactory {
             public View create(Element elem) {
             Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
             if (o instanceof HTML.Tag) {
              HTML.Tag kind = (HTML.Tag) o;
              if (kind == HTML.Tag.HR) {
                  return new MyHRuleView(elem);
           return super.create(elem);
    class MyHRuleView extends View  {
         private Color color = null;
         public void setPropertiesFromAttributes() {
              super.setPropertiesFromAttributes();
              try {color = new Color(Integer.decode((String)attr.getAttribute("color")).intValue());} catch (Exception e) {}
         public void paint(Graphics g, Shape a) {
              if (color != null) g.setColor(color);
              super.paint(g, a);
    }

  • Problem with nokia suite, wrong time showing

    Hi, I have a nokia suite 3.4.49
    I have syncronized all of my 12000 messages in nokia c3-00 to my pc
    but all of the message time is wrong +4 hours
    how can I solve this problem and make those times right ?

    May be silly to ask.. but is the time on both PC and the Phone set correct ?

  • Problems with swiping, highlighting text, not working properly

    Hello and new to forum as well as new to BB10. I have the Q10 model and really like it alot. However, these swiping techniques or gestures have me puzzled. Sometimes they work, and most times I find myself swiping the hell out of the screeen out of aggravation. Is there any way this can be tested as to working properly since it is a touch activated control?
    I really find myself swiping three times, 5 times or more, just to get to the hub. I cannot close out a screen with one swipe. It will not copy test without repeated taps. The circle pointer is hard to get on. I realize my swiping is a new technique to me, but could it be the protective cover that was put on it? Can anyone help me try to fix this very annoying problem as I am not used to repeated attempts at trying to do something so simple as closing a program or moving to another location tab. I sure would appreciate it.
    Thanks in advance.

    Hello greg30
    Welcome to the BlackBerry Support Community Forums.
    Sorry to hear you are having issues with your BlackBerry Q10 smartphone navigational gestures. Please view the follow link as it takes you to a "BlackBerry Q10 Gestures Overview".
    The screen protector is some cases can effect the gesture input on the BlackBerry Q10 smartphone screen. This is simply due to the increased thickness of the scratch resistant liner on the touch screen.
    Goose947
    Come follow your BlackBerry Technical Team on Twitter! @BlackBerryHelp
    Be sure to click Like! for those who have helped you.
    Click Accept as Solution for posts that have solved your issue(s)!

  • Xcode problem with submenu highlighted item

    This stuff works in Xcode 3.2 on my 10.6 Air, but not on Xcode 3.1.4 / on my Imac (10.5.8). This code is in an IBAction method that is connected to the menu via IB.
    [[mySubMenu highlightedItem] setState:NSOnState];  // ignored, state is not changed.
    // or 
    [[mySubMenu highlightedItem] tag];  // always returns 0 regardless of actual (int)tag. 
    // but this works fine 
    [[mySubMenu itemWithTag:myTag)] setState:NSOnState]; // the tag is read properly here, state is changed.
    I was assuming that highlightedItem meant "selected item". Is highlightedItem the usual way to detect a menu event ? What is wrong ?

    Because you have inline (via the admin) added sizes etc you will see it created inline code. Even switching to a type (CSS HTML ONLY is the one you want) to have a raw html output to CSS style it as you wish you need to go into each menu item and remove any of the style configurations and dimension sizes you added.

  • Problem with highlighting texts in Adobe Reader X

    i've a problem with the highlighting tool, it can only highlight one word at a time, it isn't possible for me to drag and highlight. i've tried updating but to no avail. in addition, i can't use the snapshoot tool either. basically any function that requires a click-and-drag motion is disabled. i'd greatly appreciate it if a kind soul may help me with this issue please!! thank you very much!

    PDF files have to be specially enabled for you to save the contents. It appears the old version of these files had this capability, but the new version does not. Without Acrobat you will be unable to save the files. If these are truly government files, you can try going to the government's website and see if you can download a copy that will allow you to save the form field data.

  • Problems with using tab -button in application

    Hi all,
    I'm working on a game, using AS 3.0 and would like to use TAB -key in the game to do certain in-game actions. With Firefox,  Chrome and Safari it works without problems and focus stays in the app. With IE8 It also works fine on some cases but for example on my friend's machine, with IE8, it switches the focus from the app to address bar and other components. We both have up-to-date flash players. I've tried to search the net for solution without great results. Is there solutions for fixing this issue in or outside AS3.0 (like using javascript?) or any ideas what's the root of the problem?
    Thanks,
    Mike

    I Too am having problems with iBooks highlighting the entire chapter if I touch the right edge of a page.  It overrides my previous highlighting making my studying useles. It's terribly frustrating! iOS 8 has been a big,big problem. Apple has to fix this.  There should be a way to undo it.  It's a terrible mess.

  • Why everytime when i try to download iTunes it says " there is a problem with this Windows Installer package. A program required for this install to complete could not be wrong". What should i do to download it?

    Why everytime when i try to download iTunes it says " there is a problem with this Windows Installer package. A program required for this install to complete could not be wrong". What should i do to download it?

    Repair your Apple software update.
    Go to START/ALL PROGRAMS/Apple Software Update. If it offers you a newer version of Apple Software Update, do it but Deselect any other software offered at the same time. Once done, try another iTunes install
    If you don't find ASU, go to Control Panel:
    START/CONTROL PANEL/Programs n Features/highlight ASU and click REPAIR,

  • RAW Highlights Problem with conversion from Canon 5D

    Hello All,
    I recently upgraded my camera from a Canon 20D to a Canon 5D. I shoot only RAW and I recently shot a couple of images of a beautiful sunset out West. I was bracketing the exposures all over the place since the light-drk contrasts were really large and the light was changing so fast. The images looked great on the Camera's LCD but, when I ran them through Aperture I got some really nasty artifacts on the conversions around the highlights. Here are examples:
    Full scene
    http://www.flickr.com/photo_zoom.gne?id=307781903&size=l
    Full scene detail:
    http://www.flickr.com/photo_zoom.gne?id=307781906&size=o
    Another example:
    http://www.flickr.com/photo_zoom.gne?id=307781905&size=l
    the problem I see is with the nasty transition from yellow to white in the blown highlight. I also don't like the broad areas of flat yellow - the tonality is completely missing. These are the default RAW settings exported to JPGs and the poor image quality of the highlights looks identical on screen between the RAW images in Aperture and these JPGs, so it's not a JPG artifact.
    I don't recall having this problem with the 20D - is the 5D conversion more difficult for Aperture? Might I be doing something wrong? Is there a way to fix this? I ran the RAW file through lightroom and it didn't have the same problem. Please help!
    -Steve G

    I have the same problems when I shot the sun rise and sun set.. It is very nasty transition from yellow to white or white to yellow from the sun. I don't think Aperture can fix that. It was over the exposure with the sun. And yes, it looks great on 2 inches LCD. I think you need to use filter when you shoot the sunset or sunrise to get the perfect lighting. Let me know, if you know the tweak with Aperture.. I will check out lightroom... I have alot of sunet and sunrise photos to correct.. and i checked out this place http://www.all-creatures.org/pics/sunset.html they have the same problems with yellow to white...

Maybe you are looking for

  • Logic Pro X-Metronome Snag:

    There is probably an easy fix for this, but after almost 2 days, I can't find it. I like to record in sections, with the metronome counting in a single bar. In Pro X, the count-in is recording over the overlapping bar. I had no problem with this in L

  • Change workspace via applescript?

    I'm constantly switching between hooking my laptop to a big monitor and working on its internal screen in a cafe or whatever. And I'm getting really tired of constantly having to do "window->workspace->some workspace" followed by "window->workspace->

  • Stock transfer between two subcontractors:

    Dear Experts, I posted some material using movement type 541 to first subcontractor(SC). This SC returned the material, for this GR is made. Now some quantities are left with this SC. Now, I want to transfer this stock with first subcontractor to ano

  • Dialog won't close in AFX CC

    I have updated my After Effects from CS6 to CC (13.0.2.3). I'm still trying to figure out why some of my scripts won't run anymore or why they make CC crash sometimes. Now, when one UI dialog calls another UI dialog, after a few clicks both of them w

  • Mixing HDV and AVCHD

    I have a camera that captures in HDV but i am looking into purchasing a camera that captures in AVCHD. Final Cut Express converts them to apple intermediate format but in order to edit in one sequence would this require additional transcoding?? Would