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