Moving JComboBox in JPanel through mouse.

Hi,
I have JComponents ( Text, CheckBox, Radio and so on..) in the JPanel. I need to allow the movement of the component in the JPanel area.
For this I am using simple logic of repianting the JPanel by changing the xy co-ordinates of the component selected. So it gives a feeling of Drag and placing the component.
I am not using DnD package.
Now my problem is when I click on JComboBox, it drops down the menu and it doesn't allow me to move the component. I cant drag the component in the screen as other components.
How can I disable the JComboBox's pop up menu. How can I move the JComboBox in my JPanel??
Thanks for the time.
Cheers.

what you could do is create a sligtly smaller Panel that held a JLabel that was really small and the pull down meny and then add that as one alowing you to move stuff by grabing the JLabel which dosn't even have to have text.

Similar Messages

  • Unable to paint (using paint() in JPanel) inside mouse listeners

    This is hard to explain but I'll do my best :)
    I've created a little game and at some point I needed to make images "move" on the JPanel (through paint()), on a checkers-based game board.
    The game works like so:
    it has a mouse listener for clicks and movement, and the main game process is THINK(), REPAINT(), which is repeated until the user wins (the above is inside a while).
    The mouse actions were added to the constructor so they are always active, THINK changes the enemy's locations, and REPAINT simply calls "paint()" again.
    The picture is either an enemy or the player, and it can only "rest" on squares.
    (e.g. point's x and y must be divided in 50).
    While doing that, I wanted to make the movement more sleek and clean,
    instead of them simply jumping from one square to the other with a blink of the eye.
    So, I've created MOVEACTOR, that "moves" an enemy or a player from its current point (actor.getPoint()) to the requested future square (futurePoint).
    //actor = enemy or player, has getPoint() that returnes the current point on the board where he rests on.
    //futurePoint = the new point where the enemy or player should be after the animation.
    //please ignore obvious stuff that has nothing to do with what I asked -- those will be deleted in the future, for they are only temporary checking extra lines and stuff.
    //also feel free to ignore the "jumpX" things. Those are just to change images, to imitate physical "jumping" animation.
    protected void moveActor(Actor actor, Point futurePoint)
              Point presentPoint = actor.getPoint();
              int x = (int)presentPoint.getX(), y = (int)presentPoint.getY();
              int addToX, addToY;
              if (futurePoint.getX() > x) addToX = 1;
              else addToX = -1;
              if (futurePoint.getY() > y) addToY = 1;
              else addToY = -1;
              Point middlePoint = new Point(x,y);
              int imageCounter = 0;
              while ( (middlePoint.getX()!=futurePoint.getX()) && (middlePoint.getY()!=futurePoint.getY()) ){
                   imageCounter++;
                   x+=addToX;
                   y+=addToY;
                   middlePoint.setLocation(x,y);
                   actor.setPoint(middlePoint);
                   /*if (imageCounter<=10) actor.setStatus("jump1");
                   else if (imageCounter<=40) actor.setStatus("jump2");
                   else if (imageCounter<=50) actor.setStatus("jump3");*/
                   repaint();
                   try {animator.sleep(1);} catch (InterruptedException e) {}
              //actor.setStatus("idle");
         }I use the above on several occasions:
    [1] When an enemy moves. Summary:
                             if (playerIsToVillainsRight) xToAdd = 50;
                             else if (playerIsToVillainsLeft) xToAdd = -50;
                             else if (playerIsOnSameRowAsVillain) xToAdd = 0;
                             if (playerIsBelowVillain) yToAdd = 50;
                             else if (playerIsAboveVillain) yToAdd = -50;
                             else if (playerIsOnSameColumnAsVillain) yToAdd = 0;
                             Point futurePoint = new Point (villainX+xToAdd, villainY+yToAdd);
                             moveActor(actors[currentVillain], futurePoint);[2] When the player moves. Summary (this is inside the mouseClicked listener):
    //mouseLocation = MouseWEvent.getPoint();
    //stl, str, etc = rectangles that represents future location of the player on the board.
              if (waitingForPlayer) {
                   if (stl.contains(mouseLocation) && !hoveringVillain(stl)) {
                        moveActor(actors[0], stl.getLocation());
                        waitingForPlayer = false;
                   if (str.contains(mouseLocation) && !hoveringVillain(str)) {
                        moveActor(actors[0], str.getLocation());
                        waitingForPlayer = false;
                   if (sbl.contains(mouseLocation) && !hoveringVillain(sbl)) {
                        moveActor(actors[0], sbl.getLocation());
                        waitingForPlayer = false;                                   
                   if (sbr.contains(mouseLocation) && !hoveringVillain(sbr)) {
                        moveActor(actors[0], sbr.getLocation());
                        waitingForPlayer = false;
    SO ... WHAT IS THE QUESTION?!?
    What I see when I run the game:
    the animation of the enemy (first code) works, but the animation of the player (second code, inside the mouse listeners) -- doesn't!
    The purpose of the moveActor is to move the enemy or player pixel by pixel, until its in the future point,
    instead of skipping the pixels between the squares and going straight for the future location.
    So what comes out is, that the enemy is moving pixel by pixel, and the player simply jumps there!
    I doublechecked and if I use moveActor with the player OUTSIDE the mouse listener, it works (i think).
    Any ideas what is the source of this problem?
    Hope I made myself clear enough :D
    Thanks,
    Eshed.

    I don't know if thats what happens, nor how to fix the thread problems. The mosue actions are "threaded" by default, no? And the moving thing happens after the mouse was clicked, and if the enemy's moving the user can still move his mouse and get responses, like "enemy didn't move yet" and stuff.
    Here's the complete GamePanel.java:
    //drawings
    import javax.swing.ImageIcon;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    //events
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    //tools
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.MediaTracker;
    import java.awt.Dimension;
    //panels, buttons, etc
    import javax.swing.JPanel;
    /** The Game Panel.
    *The panel's size is 500x500, and each square is squaresized 50.
    *This is where the game actually "exists". Here its being updated, drawn, etc.*/
    public class GamePanel extends JPanel implements Runnable
         private static final int PWIDTH = 500;                              //Width of the panel.
         private static final int PHEIGHT = 500;                              //Height of the panel.
         private static final int SQUARESIZE = 50;                         //Size of each square in the panel.
         private boolean working = false;                                   //Game keeps going until this is FALSE.
         private volatile Thread animator;                                   //The animation thread.
         private ImageIcon stand,fall;                                        //Images for the background - ground and water.
         private static ImageHandler ih;                                        //An image handler for image loading.
         private int numOfImages = 0;                                        //Number of total images (max image qunatity).
         private Actor[] actors;                                                  //The actors: [0] is the player, rest are enemies.
         private Point mouseLocation;                                        //Saves the current mouse location for checking where the mouse is
         protected Rectangle stl, str, sbl, sbr;                              //squares around the player, for mouse stuff.
         protected Rectangle v1, v2, v3, v4, v5;                              //squares around each villain, for mouse stuff.
         protected Rectangle wholeBoard = new Rectangle(0,0,PWIDTH,PHEIGHT);
         protected boolean waitingForPlayer = true;
         private int currentVillain = 1;
         private boolean inSight = false;
         // in methods other than the listeners.
         /** Waits for the Window (or whatever this panel loads in) to settle in before doing anything.*/
         public void addNotify()
              super.addNotify();                                                                           //When the super finishes...
              go();                                                                                                         //..go, go, go!
         /** Starts the game.*/
         private void go()
              if (animator==null || !working)     {                                        //if the game isn't in process,
                   animator = new Thread(this);                                        //make the animator as the main process,
                   animator.start();                                                                      //and start it (because of the runnable it launches "run()".
         /**Constructor of the Game Panel.*/
         public GamePanel()
              numOfImages = 14;                                                                      //Total image num.
              ih = new ImageHandler(this,numOfImages);               //Setting a new image handler for the images.
              ih.addImage("player_idle", "images/p_idle.png");          //Adding images.
              ih.addImage("villain_idle", "images/v_idle.png");
              ih.addImage("stand", "images/stand.gif");
              ih.addImage("fallpng", "images/fall.png");
              ih.addImage("fall", "images/fall.gif");
              ih.addImage("ghost", "images/ghost.gif");
              ih.addImage("villain_angry", "images/v_angry.png");
              ih.addImage("player_angry", "images/p_angry.png");
              ih.addImage("player_jump1", "images/p_j1.gif");
              ih.addImage("player_jump2", "images/p_j2.gif");
              ih.addImage("player_jump3", "images/p_j3.gif");
              ih.addImage("villain_jump1", "images/v_j1.gif");
              ih.addImage("villain_jump2", "images/v_j2.gif");
              ih.addImage("villain_jump3", "images/v_j3.gif");
              setPreferredSize(new Dimension(PWIDTH,PHEIGHT));     //Setting size of the panel.
              setFocusable(true);                                                                                //This and the next makes the window "active" and focused.
              requestFocus();
              /** Mouse hovering settings.*/
              addMouseMotionListener( new MouseMotionAdapter()
                   /** When the mouse is moving, do these stuff.*/
                   public void mouseMoved(MouseEvent e1)
                         *  |  stl  |       | str   |          stl = squareTopLeft
                         *  |_______|_______|_______|       str = squareTopRight
                        *   |       |current|       |         current = player's location
                        *   |_______|_______|_______|       sbl = squareBottomLeft
                        *   |  sbl  |       |  sbr  |       sbr = squareBottomRight
                        *   |_______|_______|_______|
                        mouseLocation = e1.getPoint();
                        Dimension defaultSquareDimension = new Dimension(50,50);
                        //current-player-location points
                        Point topLeft = new Point((int)actors[0].getPoint().getX(), (int)actors[0].getPoint().getY());
                        Point topRight = new Point((int)actors[0].getPoint().getX()+50, (int)actors[0].getPoint().getY());
                        Point bottomLeft = new Point((int)actors[0].getPoint().getX(), (int)actors[0].getPoint().getY()+50);
                        Point bottomRight = new Point((int)actors[0].getPoint().getX()+50, (int)actors[0].getPoint().getY()+50);
                        //four-squares-around-the-player points
                        //T = top, B = bottom, R = right, L = left
                        Point ptl = new Point((int)topLeft.getX()-50,(int)topLeft.getY()-50);
                        Point ptr = new Point((int)topRight.getX(),(int)topRight.getY()-50);
                        Point pbl = new Point((int)bottomLeft.getX()-50,(int)bottomLeft.getY());
                        Point pbr = new Point((int)bottomRight.getX(),(int)bottomRight.getY());
                        //ghosts
                        stl = new Rectangle (ptl, defaultSquareDimension);
                        str = new Rectangle (ptr, defaultSquareDimension);
                        sbl = new Rectangle (pbl, defaultSquareDimension);
                        sbr = new Rectangle (pbr, defaultSquareDimension);
                        Rectangle player = new Rectangle(topLeft, defaultSquareDimension);     //rectangle of player
                        if (stl.contains(mouseLocation) && !hoveringVillain(stl))
                             actors[8] = new Actor("ghost", ptl);
                             else actors[8] = null;
                        if (str.contains(mouseLocation) && !hoveringVillain(str))
                             actors[9] = new Actor("ghost", ptr);
                             else actors[9] = null;
                        if (sbl.contains(mouseLocation) && !hoveringVillain(sbl))
                             actors[10] = new Actor("ghost", pbl);
                             else actors[10] = null;
                        if (sbr.contains(mouseLocation) && !hoveringVillain(sbr))
                             actors[11] = new Actor("ghost", pbr);
                             else actors[11] = null;
                   private boolean hoveringVillain(Rectangle r)
                        boolean onVillain = false;
                        for (int i=1; i<=5 && !onVillain; i++) onVillain = actors.getRect().equals(r);
                        return onVillain;
              /** Mouse-click settings.
              Note: only usable after moving the mouse. /
              addMouseListener (new MouseAdapter()
                   /** When the mouse button is clicked */
                   public void mouseClicked (MouseEvent me)
                        mouseClickedAction(me);
         private boolean hoveringVillain(Rectangle r)
              boolean onVillain = false;
              for (int i=1; i<=5 && !onVillain; i++) onVillain = actors[i].getRect().equals(r);
              return onVillain;
         public void mouseClickedAction(MouseEvent me)
              System.out.println("Point: "+me.getX()+","+me.getY());
              if (waitingForPlayer) {
                   //causes error if the mouse wasn't moved uptil now. try it.
                   mouseLocation = me.getPoint();
                   if (stl.contains(mouseLocation) && !hoveringVillain(stl)) {
                        moveActor(actors[0], stl.getLocation());
                        waitingForPlayer = false;
                   if (str.contains(mouseLocation) && !hoveringVillain(str)) {
                        moveActor(actors[0], str.getLocation());
                        waitingForPlayer = false;
                   if (sbl.contains(mouseLocation) && !hoveringVillain(sbl)) {
                        moveActor(actors[0], sbl.getLocation());
                        waitingForPlayer = false;                                   
                   if (sbr.contains(mouseLocation) && !hoveringVillain(sbr)) {
                        moveActor(actors[0], sbr.getLocation());
                        waitingForPlayer = false;
              } else MiscTools.shout("Wait for the computer to take action!");
              if (actors[0].getPoint().getY() == 0){
                   for (int i=1; i<=5; i++){
                             actors[i].setStatus("angry");
                   //repaint();
                   MiscTools.shout("Game Over! You Won!");
         /** First thing the Game Panel does.
         Initiating the variables, and then looping: updating, painting and sleeping./
         public void run() {
    Thread thisThread = Thread.currentThread();                                                  //Enables the restart action (two threads needed).
    init();                                                                                                                                            //Initialize the variables.
    while (animator == thisThread && working){                                                  //While the current thead is the game's and it's "on",
                   think();                                                                                                                             //Update the variables,
                   repaint();                                                                                                                             //Paint the stuff on the panel,
                   try {Thread.sleep(5);} catch (InterruptedException ex) {}                    //And take a wee nap.
         /** Initializing the variables.*/
         private void init()
              currentVillain = 1;
              working = true;                                                                                //Make the game ready for running.
              inSight = false;
              actors = new Actor[12];                                                                      //Six actors: player and 5*villains.
              actors[0] = new Actor("player", 200, 450);                                             //The first actor is the player.
              int yPoint = 50;                                                                           //The Y location of the villains (first row).
              /* ACTORS ON TOP, RIGHT, LEFT
              actors[1] = new Actor ("villain", 0, 350);
              actors[2] = new Actor ("villain", 0, 150);
              actors[3] = new Actor ("villain", 50, 0);
              actors[4] = new Actor ("villain", 250, 0);
              actors[5] = new Actor ("villain", 450, 0);
              actors[6] = new Actor ("villain", 450, 200);
              actors[7] = new Actor ("villain", 450, 400);
              /* ACTORS ON TOP*/
              for (int i=1; i<actors.length-4; i++){                                                  //As long as it doesnt go above the array...
                   actors[i] = new Actor ("villain", yPoint, 0);                                   //init the villains
                   actors[i].setStatus("idle");
                   yPoint+=100;                                                                           //and advance in the Y axis.
         /** Updating variables.*/
         private void think()
              if (!waitingForPlayer){
                   //initialize
                   int playerX = (int)actors[0].getPoint().getX();
                   int playerY = (int)actors[0].getPoint().getY();
                   boolean moved = false;
                   wholeBoard = new Rectangle(0,0,500,500);     //needed to check whether an actor is inside the board
                   //for (int in = 0; in<=5; in++) actors[in].setStatus("idle"); //"formatting" the actor's mood
                   if (playerY <= 1000) inSight = true;     //first eye contact between the player and villains.
                   int closestVillainLevel = 0;
                   int[] vills = closestVillain();
                   int moveCounter = 0;
                   if (inSight) {
                        while (!moved){               //while none of the villains made a move
                        moveCounter++;
                        if (moveCounter == 5) moved = true;
                        else{
                             currentVillain = vills[closestVillainLevel];
                             int villainX = (int)actors[currentVillain].getPoint().getX();
                             int villainY = (int)actors[currentVillain].getPoint().getY();
                             //clearing stuff up before calculating things
                             boolean playerIsBelowVillain = playerY > villainY;
                             boolean playerIsAboveVillain = playerY < villainY;
                             boolean playerIsOnSameRowAsVillain = playerY == villainY;
                             boolean playerIsToVillainsRight = playerX > villainX;
                             boolean playerIsToVillainsLeft = playerX < villainX;
                             boolean playerIsOnSameColumnAsVillain = playerX == villainX;
                             //System.out.println("\n-- villain number "+currentVillain+" --\n");
                             int xToAdd = 0, yToAdd = 0;
                             if (playerIsToVillainsRight) xToAdd = 50;
                             else if (playerIsToVillainsLeft) xToAdd = -50;
                             else if (playerIsOnSameRowAsVillain) xToAdd = 0;
                             if (playerIsBelowVillain) yToAdd = 50;
                             else if (playerIsAboveVillain) yToAdd = -50;
                             else if (playerIsOnSameColumnAsVillain) yToAdd = 0;
                             Point futurePoint = new Point (villainX+xToAdd, villainY+yToAdd);
                             if (legalPoint(futurePoint)){
                                  moveActor(actors[currentVillain], futurePoint);
                                  moved = true;
                                  //System.out.println("\nVillain "+currentVillain+" is now at "+actors[currentVillain].getPoint());
                             else closestVillainLevel=circleFive(closestVillainLevel);
                        } //end of else
                        } //end of while
                        //currentVillain = circleFive(currentVillain); //obsolete
                   } //end of ifInSight
                   waitingForPlayer = true;
         private boolean legalPoint(Point fp)
              return (wholeBoard.contains(fp) && !onPeople(fp) && legalSquare(fp));
         private boolean legalSquare(Point p)
              if ( (p.getX()==0 || p.getX()%100==0) && (p.getY()/50)%2!=0 ) return true;
              if ( (p.getX()/50)%2!=0 && (p.getY()==0 || p.getY()%100==0) ) return true;
              return false;
         //return the closest villain to the player, by its level of distance.
         public int[] closestVillain()
              //System.out.println("Trying to find the closest villain...");
              double[] gaps = new double[5];     //the distances array
              //System.out.println("The villains' distances are: ");
              for (int i=0; i<5; i++){
                   gaps[i] = distanceFromPlayer(actors[i+1].getPoint());     //filling the distances array
                   //System.out.print(gaps[i]+", ");
              int[] toReturn = new int[5];
              double smallestGapFound;
              double[] arrangedGaps = smallToLarge(gaps);
              for (int level=0; level<5; level++){
                   smallestGapFound = arrangedGaps[level];
                   for (int i=1; i<=5; i++){
                        if (smallestGapFound == distanceFromPlayer(actors[i].getPoint())){
                             toReturn[level] = i;
              return toReturn;
         private double[] smallToLarge(double[] nums)
              //System.out.println("\nArranging array... \n");
              double[] newArray = new double[5];
              int neweye = 0;
              double theSmallestOfTheArray;
              for (int i=0; i<nums.length; i++){
                   theSmallestOfTheArray = smallest(nums);
                   //System.out.println("\t\t>> Checking whether location "+i+" ("+nums[i]+") is equal to "+theSmallestOfTheArray);
                   if (nums[i] == theSmallestOfTheArray && nums[i]!=0.0){
                        //System.out.println("\t\t>> Adding "+nums[i]+" to the array...");
                        newArray[neweye] = nums[i];
                        //System.out.println("\t\t>> Erasing "+nums[i]+" from old array...\n");
                        nums[i] = 0.0;
                        neweye++;
                        i=-1;
              /*System.out.print("\nDONE: ");
              for (int i=0; i<newArray.length; i++)
                   System.out.print("["+newArray[i]+"] ");
              System.out.println();*/
              return newArray;
         private double smallest (double[] nums)
                   //System.out.print("\tThe smallest double: ");
                   double small = 0.0;
                   int j=0;
                   while (j<nums.length){               //checking for a starting "small" that is not a "0.0"
                        if (nums[j]!=0.0){
                             small = nums[j];
                             j = nums.length;
                        } else j++;
                   for (int i=1; i<nums.length; i++){
                        if (small>nums[i] && nums[i]!=0.0){
                             small = nums[i];
                   //System.out.println(small+".");
                   return small;
         private double distanceFromPlayer(Point vp)
              Point pp = actors[0].getPoint(); //pp=plaer's point, vp=villain's point
              double x = Math.abs(vp.getX() - pp.getX());
              double y = Math.abs(vp.getY() - pp.getY());
              return Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
         private int circleFive(int num)
                   if (num>=5) return 0;
                   else return num+1;
         private boolean onPeople(Point p)
              for (int jj=0; jj<=5; jj++)
                   if (jj!=currentVillain && p.equals(actors[jj].getPoint()))
                        return true;
              return false;
         /** Painting the game onto the Game Panel.*/
         public void paintComponent(Graphics g)
              Graphics2D graphics = (Graphics2D)g;                                                            //Reset the graphics to have more features.
              //draw bg
              graphics.setColor(Color.white);                                                                                //"format" the panel.
              graphics.fillRect(0,0,500,500);
         char squareType = 'f';                                                                                                    //First square's type (stand or fall).
         for (int height=0; height<PHEIGHT; height=height+SQUARESIZE){     //Painting the matrix bg.
                   for (int width=0; width<PWIDTH; width=width+SQUARESIZE){
                        if (squareType=='f') {                                                                                               //If a "fall" is to be drawn,
                             ih.paint(graphics, "fallpng", new Dimension(width,height));          //Draw a non-animated image to bypass white stuff.
                             ih.paint(graphics, "fall", new Dimension(width,height));               //Draw the water animation.
                             squareType = 's';                                                                                                    //Make the next square a "stand".
                        } else if (squareType=='s'){                                                                                //If a "stand" is to be drawn,
                             ih.paint(graphics, "stand", new Dimension(width,height));          //Draw the ground image,
                             squareType = 'f';                                                                                                    //and make the next square a "fall".
                   if (squareType=='f') squareType = 's';                                                                 //After finishing a row, switch again so
                   else squareType = 'f';                                                                                                    // the next line will start with the same type (checkers).
              for (int i=actors.length-1; i>=0; i--){                                                                           //Draw the actors on the board.
                   if (actors[i]!=null)
                        ih.paint(graphics, actors[i].currentImage(), actors[i].getPoint());
         /** Restart the game.
         Or, in other words, stop, initialize and start (again) the animator thread and variables./
         public void restart()
              System.out.println("\n\n\nRESTARTING GAME\n\n\n");
              animator = null;                                                                                                                   //Emptying the thread.
              init();                                                                                                                                                 //Initializing.
              animator = new Thread(this);                                                                                     //Re-filling the thread with this panel's process.
              animator.start();                                                                                                                   //launch "run()".
         protected void moveActor(Actor actor, Point futurePoint)
              Point presentPoint = actor.getPoint();
              int x = (int)presentPoint.getX(), y = (int)presentPoint.getY();
              int addToX, addToY;
              if (futurePoint.getX() > x) addToX = 1;
              else addToX = -1;
              if (futurePoint.getY() > y) addToY = 1;
              else addToY = -1;
              Point middlePoint = new Point(x,y);
              int imageCounter = 0;
              while ( (middlePoint.getX()!=futurePoint.getX()) && (middlePoint.getY()!=futurePoint.getY()) ){
                   imageCounter++;
                   x+=addToX;
                   y+=addToY;
                   middlePoint.setLocation(x,y);
                   actor.setPoint(middlePoint);
                   /*if (imageCounter<=10) actor.setStatus("jump1");
                   else if (imageCounter<=40) actor.setStatus("jump2");
                   else if (imageCounter<=50) actor.setStatus("jump3");*/
                   repaint();
                   try {animator.sleep(1);} catch (InterruptedException e) {}
              //actor.setStatus("idle");

  • Shortcut for moving forward and backward through Time Machine

    It seems obvious that there should be keyboard shortcuts for moving backward and forward through time in the Time Machine. Anyone know how?

    V.K. wrote:
    it might seem obvious but AFAIK there are no shortcuts for that. use the mouse.
    I can't imagine replacing a simple mouse click with something like
    Cmd-Ctl-Shift-Fn12-page up
    It's noticeable that the menu disappears when entering TM, meaning that the usual assignments of shortcuts in the KB menu have, at least for the present, unknown values, if any at all.
    What kind of shortcut would take me back to December 25, 2007 anyway? The trackpad and trackpad bar work.
    It's possible to open TM with a shortcut or script, but from there one is on the dark side.
    Message was edited by: nerowolfe

  • Problem with JPanel's mouse listener!

    I am developing a Windows Explorer-like program. I have an JPanel and added JLabels to that panel to reprensent the folders. I think, I kind of have to add mouse listener to JPanel to interact with mouse clicks, gaining and losing focus of JLabels etc. instead of adding every JLabel to mouse listener. So when I added to JPanel a mouse listener, it didn't work how I had expected. When I clicked on labels mouse click events didn't fire but when I clicked somewhere else in the panel it did fire. Is this a bug or am I using mouse listener incorrectly??
    Thank for advance :)
    Here is my JPanel's mouse listener ->
    public void mouseClicked(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    System.out.println("Mouse Clicked");
    Component c = this.getComponentAt(x,y);
    if(c instanceof JLabel){
    JLabel label = (JLabel) c;
    label.setBackground(Color.LIGHT_GRAY);
    }

    My main problem is as in windows explorer (if CTRL or SHIFT not pressed) there is only one selected folder (in my case JLabel) and transfering "selection" to one label to another might need lots of extra code.. So I thought using JPanel's mouse listener can overcome this handling problem. But if you are saying, this is the way it has to be done, then so be it :D :D

  • I cannot select previously searched items in google toolbar search through mouse, I have to selct it by keyboard or retype it.

    In firefox 4 I cannot select previously searched items in google toolbar search through mouse, I have to selct it by keyboard or retype it.
    Also during switching between tabs I notice black screen.

    I just tried clicking the left button of the mouse BEFORE placing the pointer above the drop-down arrow of the Google search and worked. If the word was deep down the list, i scrolled down the wheel of the mouse. Always keeping the left button pressed and releasing it once i had pointed my choice.

  • How to show popup message in jpanel when mouse is moved over some area

    i have made a bar graph for my database in jpanel. now i want to show the proper data in popup when user moves mouse over apprpriate bar in jpanel. i would like to know is there is any way to do this. i need help as i m new in the field of java. i am making birthday remainder service for user. i am using j2se.

    i want to show the proper data in popup when user moves mouse over apprpriate bar Sounds like you want to use a tooltip. Is your "bar"
    a) a real component ?
    If so, then just use setToolTipText(...) method
    b) a graphical drawing?
    Then you will need to convert the mouse coordinates and display a tool tip based on the coordinats. The SwingSet example that comes with the JDK has an example of this:
    change to directory: j2sdk1.4.2\demo\jfc\SwingSet2
    then execute >java -jar SwingSet2.jar

  • JComboBox selection actions on mouse and enter only

    I am driving some processing off of selections in a JComboBox.
    The ItemListener goes into action when the user mouse clicks on an item (this is good), but also when an item is arrowed through (bad).
    I want to wait until the person hits enter before starting my processing.
    Ideally the JComboBox popup could close before the start of my processing.
    The direction I am currently headed: I notice that when the mouse clicks, and when enter is hit, the JComboBox popup closes. Since these are the 2 user events I want to respond to, this fact interests me greatly. Is there any way to see and use the event of the popup closing?
    Note: I don't care so much about the direction I am thinking now as much as a solution to the overall problem.

    Try to register a KeyListener to the JComboBox or to its editor (if its editable) and react to the keyReleased Event. In the corresponding listener method you have to query the key typed and react to the ENTER key being pressed. Also get away from the ItemListener as the JComboBox / ItemListene combination is not the best the guys at sun farbricated...

  • Moving xy graph cursor with mouse and programmab​ly controllin​g snap to point

    Hi,
    I have run into a bit of a problem. I am trying to create a program which allows a user to select a location on an XY graph by simply clicking in the vacinity of the plot. Most of it is working, however I find that I can't programmably control the snap to point function reliably.
    I hope this is a clear outline of the problem:
    - The cursor starts in a Free state, so that when the
    user clicks in the plot area, I can set the cursor
    position to the nearest point by setting the
    CursorPosition using the graph's property node.
    - Maybe the user didn't like the chosen location and
    wants to drag the cursor over a bit. Ok, user drags
    the cursor to a new position.
    - Now th
    e cursor position is probably not exactly on
    the plot trace. If, at this point, I set the cursor
    to Snap To Point, the cursor does not snap to the
    nearest point on the graph (relative to its current
    position), but instead to the last place a _mouse_
    action placed it.
    - Immediately after the new location has been set,
    the cursor state has to be reset to free in case I
    need to programmably move the cursor again (I
    can't seem to programmably control the mouse in
    any state but Free)
    How do I go about getting the cursor to snap to the closest point at it's new location? I'm at a loss.
    Any insight you might have would be greatly appreciated.
    Thanks much!
    Tere

    So what is the question about... I have to use XY graph in my program. It is used in Loop while cycle. It shows the statistic of a variable. I am using cursors in this graph to check the actual value of a variable in different period of time. But there are 7 variables and it is extremely hard for user to check each value independently. So I tried to make them moving on the X axis (TIME) together using the property node (cursors reading the position (only X axis, Y axis status lock to plot) of the major cursor and follow it... Everything looks great? But it did not work when I am trying to move the major cursor manually on graph... It works only when I am using the cursor movement buttons... But they work very slowly when there is a lot of data in graph.
    I want to find out is it possible to make seven coursers mouthing together By the X axe and be Locked each at its plot by Y axe manually (Using mouse moving on a graph). Is it possible? If it is than how to do it?

  • Moving the player to the mouse position.

    I have a question about moving and animated player symbol to the mouse location on a MouseDown event. Right now I have it set up to do an easing so that I can control how fast the player moves to the location. Problem is that it is done with easing. I don' t like the easing because the velocity of starts really fast and then slows down before it reaches the mouseX and mouseY location. I would like just a plain ol' stroll from the player location to the mouse location on the MouseDown event. Here is my code:
    package
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class PlayerToMouse extends MovieClip
      //Declare constants
      private const EASING:Number = 0.1;
      //Declare variables
      private var _targetX:Number;
      private var _targetY:Number;
      private var _vx:Number;
      private var _vy:Number;
      public function PlayerToMouse()
       player.gotoAndStop(1);
       //Initialize variables
       _targetX = mouseX;
       _targetY = mouseY;
       _vx = 0;
       _vy = 0;
       //Add event listeners
       stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
      private function onEnterFrame(event:Event):void
       player.play();
       //Calculate the distance from the player to the mouse
       var dx:Number = _targetX - player.x;
       var dy:Number = _targetY - player.y;
       var distance = Math.sqrt(dx * dx + dy * dy);
       //Move the object if it is more than 1 pixel away from the mouse
       if (distance >= 1)
        //move the player
        _vx = (_targetX - player.x) * EASING;
        _vy = (_targetY - player.y) * EASING;
        //move the player
        player.x +=  _vx;
        player.y +=  _vy;
       else
        player.gotoAndStop(1);
        trace("Player reached target");
        removeEventListener(Event.ENTER_FRAME,onEnterFrame);
      private function onMouseDown(event:Event):void
       _targetX = mouseX;
       _targetY = mouseY;
       addEventListener(Event.ENTER_FRAME,onEnterFrame);
    Any input would be appretiated. I am a beginner and my mindset for the best coding procedure is not there yet.
    Shiim

    I didn't exactly figure in the constants of _vx and _vy, but I took a bit of your idea and created something that works to my liking. The downfall to my code is that the calculations in the onEnterFrame causes the player to not fully reach the destination, thus the animation never stops. I forced it to stop with an if statement that comes close enough to not be noticeable.
    Here is the edited code:
    if (distance >= 1)
        _vx = (dx /30);
        _vy = (dy /30);
        //move the player
        player.x +=  _vx;
        player.y +=  _vy;
        if (distance <= 15)
         _vx = 0;
         _vy = 0;
         player.gotoAndStop(4);
         removeEventListener(Event.ENTER_FRAME,onEnterFrame);
    Thanks for the input Ned.
    If anyone has any ideas to make this better, feel free to comment. I'm a beginner and can use all the advice I can get...
    Shiim

  • MOVED: K9A2 Platinum trouble with mouse.

    This topic has been moved to AMD64 ATI/SiS/VIA boards.
    https://forum-en.msi.com/index.php?topic=145567.0

    Enter SafeMode and DeviceManager. What relevant mouse(s) and possibly HID-devices do you find?
    The skipping mouse can come from an auto-starting program or virus. That is something that would not be seen in SafeMode, too.

  • Why is my desk top moving when i move my mouse

    why is my desk top moving when i move my mouse

    Turn off Zoom from the Universal Access and Keyboard & Mouse panes of System Preferences.
    (96210)

  • Bluetooth- my mouse is moving probably by neighbor's mouse. Is it okay?

    I moved in an apartment building, and use my MacBook Pro near window which is closed to neighbor's window.... And found that my mouse (on MacBook Pro) connected with bluetooth is moving by someone else mouse.
    It happened when my daughter uses old mac's mouse before. But this time she doesn't use it.
    My question is this: Is it SECURE or safe if my mouse is controlled by someone else mouse?
    Thanks much in advance for help!

    AS far as I know, nothing can be done with a mouse that is controlling your system (unless someone could see your screen. The effective range of BT devices is about 30 feet (10 meters).
    Barry

  • Swipe Effect through mouse click

    Hi,
    I am new to animations and trying to add few in my application.
    (1)Whenever I am navigating to different page (by a click or double click of a node ), I want to have an animation -- old page moving towards left and getting removed altogether and new page getting loaded from right hand side.
    Something like a page swipe in ios/android devices . However my application is not for touch enabled devices for now.
    Is this possible though javafx 2.x . If so , could you direct me to appropriate sample/api.
    (2) Can a click of a mouse be mapped to Gesture Events. For example - I click a link/button for navigation and application takes it as a Swipe Event and hence navigates to a different page giving swipe effect ?
    Thanks

    (1) Whenever I am navigating to different page (by a click or double click of a node ), I want to have an animation -- old page moving towards left and getting removed altogether and new page getting loaded from right hand side. Yes, see:
    http://docs.oracle.com/javafx/2/animations/basics.htm#CJAJJAGI (Transitions)
    http://docs.oracle.com/javafx/2/api/javafx/animation/package-summary.html (Animation API)
    http://www.e-zest.net/blog/sliding-in-javafx-its-all-about-clipping/ (Sliding in JavaFX)
    http://fxexperience.com/2012/03/canned-animations/ (Animation Lib)
    http://gist.github.com/1437374 (Panel Slide Effect)
    (2) Can a click of a mouse be mapped to Gesture EventsI don't think this can be done with the public API. One way to do it would be to add a filter on your layout pane which consumes the mouse click event and generates a SwipeEvent, but SwipeEvent has no constructor - so this would not work. There is an existing Jira request to create public constructors for event classes so that this kind of thing could be done. Perhaps you could make use of private impl_ apis or com.sun classes to allow this to be done with JavaFX 2.2, but I wouldn't recommend that approach.
    Also it is probably best to place separate questions in separate posts for ease of searching etc.

  • Apps moved to SD card are moved back to device through updates by Google Play

    Hello This happens on both my Z3 Compact (5.0.2 - v23.1.A.1.28) and Z3 Tablet Compact (5.1.1 - v23.4.A.0.546) This is really annoying. After running out of space on the devices, I went through all the trouble of moving a bunch of large apps to the SD card but then halfway through an update by Google Play Store found that the devices had run out of space again. A quick look confirmed that the "move to SD card" option was again enabled for apps previously moved but then subsequently updated through the Store. TIA

    When you move an app to the external SD-card you're only moving the apk-file (the file that you download from Google Play). You can't move the apps private data and databases.
    Say for example that you download an app from Google Play where the download from Google Play is 40MB. After it's installed you go to Settings -> Apps -> On SD Card and open that app. If you here check "App on device" and then move it to the SD card you will see that after moving it, "App on device" will have decreased with the file size you downloaded from Google Play (40MB).
    The apps are moved to the folder .android_secure on the root of the external SD but you will probably not find this folder using a file manager in the phone. You can see it if you were to connect the phone to a computer in MSC-mode though.
    I beliveve the mount point for it in the phone is /mnt/asec
    For more information, also see http://developer.android.com/guide/topics/data/install-location.html
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • MOVED: MSI Z77A-GD65: All mouse & keyboards (usb) are acting up

    This topic has been moved to [Intel Core-iX boards].
    https://forum-en.msi.com/index.php?topic=160855.0

    Quote from: flobelix on 12-August-12, 01:08:02
    It is supported, Froggy just meant you'd possibly require an update. Since you have the latest now that's not the problem.
    Have you tried mouse and Keyboard in other usb ports. Sure it is keyboard/mouse and not the system beeing generally laggy. Have you run a virus check?
    Ok, thanks for replying.
    I've tried all ports, and changing to a different USB connectors on the motherboard.
    I do have Security Essentials installed, and it's not an virus issue.
    Also I just recalled that during the installation of Windows 7 Pro the keyboard and mouse was also stuttering a bit.
    This was after I've cleaned the HDD and so did a full clean install.
    I've tried using the MSI LiveUpdate tool to update all my drivers, but no luck there either.
    As I mentioned, never had this problem before and after having this issue for 2 days now I notice that it almost looks like the keyboard and mouse are "reconnecting". Both mouse and keyboard light flashes for a second, and then it works but happends again randomly.
    Just weird that the other devices aren't affected, like my 4G modem that I use for internet. No problems there.
    ... But when I'm in BIOS there is no problem whatsoever with the keyboard and mouse.

Maybe you are looking for

  • Data Migration from Snow Leopard to Yosemite

    I purchased a new Mini to use as a file server.  The old mini is still using Snow Leopard and cannot upgrade to Yosemite.  Am I going to have problems once I install the old system from time machine onto the new mini?

  • PART 2 ledger posting problem

    Hi All, I n SAP CIN (Country Version India) J1IEX (Excise invoice part 2) posted . Part 1 ledger got updated but part 2 value is coming as 0 while checking in J1I7.In MIGO base value and excise duties are captured correctly. How to get the values upd

  • Canceling invoice,

    Dear SAP Gurus, After invoice verification  for import PO i found that some PO condition has to be changed, I have done invoice verification for delivery cost only.and yet i have not done GR, I CANCELED the INVOICE DOCUMENT using t.code MIR4, Now whe

  • Is there a limit to how many USB/Fire devices you can connect?

    I don't like the idea of having limited USB/Firewire inputs as I plan on having a ... 1). USB audio interface for Logic Express 2). USB connector for both an HD camcorder and a Nikon camera (although I most likely will switch between the two) 3). dig

  • Toplink and authentication

    Does anyone know where I can find information about using toplink but authenticating user access via OID? I have been looking but have not had much success linking the two topics. Thanks for any help you can provide.