0

Im trying to write a gui that will change labels based on the mouseClick. I implemented a click and drag system, but the problem is that it only works when it is in fullscreen? Can anyone tell me how to make my points relative to just the frame? Basically, my JLabels location is off and i need it to match the panel not the screen:

           int xbegin = 0, ybegin = 0, xend, yend= 0;
           Point px, p2x = null;
           for(int a = 0; a < states.size(); a++ ){
           if(states.get(a).getIcon() == yellowIcon){
            self = true;
            xbegin = states.get(a).getX();
            ybegin = states.get(a).getY();
            p2x  = (SwingUtilities.convertPoint(states.get(a), xbegin, ybegin, jPanel2));
            states.get(a).setIcon(rectangleIcon);
            yellow = false; 
        }
        else if(states.get(a).getIcon() == yellow2Icon){
                   System.out.println("this is zarir");
            xend = states.get(a).getX();
            yend = states.get(a).getY();
            px = (SwingUtilities.convertPoint(states.get(a), xend, yend,     jPanel2));
            Shape rect = new Rectangle2D.Double(p2x.x,60,px.x-p2x.x,2);
            ShapeIcon transit = new ShapeIcon(rect, Color.red);
            JLabel transitLabel = new JLabel(transit);
            transition.add(transitLabel);
            transitLabel.setText("Define Transition");
            transitLabel.setBounds(p2x.x,70,px.x-p2x.x, 200); 
            System.out.println(transitLabel.getBounds());
            states.get(a).setIcon(rectangleIcon);
            jPanel2.add(transitLabel);
            jPanel2.revalidate();
            jPanel2.repaint(); 
             }
           }
  }                                     

Im getting mouseCoordinates each time i click my panel but I dont recieve any coordinates when i click my label? Any tips for GUIs in general would be really helpful

zarir
  • 29
  • 6
  • Can you post a screenshot of what it looks like and what you expect it to be – CMPS Jan 16 '16 at 04:53
  • Did you add a `MouseListener` to the label? – MadProgrammer Jan 16 '16 at 05:22
  • 2
    Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer Jan 16 '16 at 05:23
  • For [example](http://stackoverflow.com/a/5312702/230513). – trashgod Jan 16 '16 at 10:13

0 Answers0