I need someone familiar with the properties of JLabel to understand the way around this problem. Basically, I have two labels, label A and label B. When the user clicks label A it is supposed to show label B next to it. Simple enough. However, the only way I can get B to show us is by setting A's visible modifier to false. Once A is visible, B is no longer shown. No, the labels do not overlap.
Here is the specific code in question. It is located in the repaint method of my extension of JPanel. Don't bother looking at the various variables. its the commented line that I have a problem with. If I put it in place this code works, if I do not the last add line might add the label but it doesn't show up in the Panel.
Finally, as a side note, I also have a slightly smaller problem.. if anyone knows how to fix it great. My zoom buttons only seem to work in the Panel which they affect. Once I move them to a separate Panel and call the zoom methods remotely, nothing happens. I have tried calling the repaint method in the zoom methods, and have also tried having the parent of the Panel to be zoomed to be repainted. Nothing. I can't even repaint the Panel remotely from a separate Panel, even though they are in the same Frame.
But as I said, my biggest problem is with the Label visibility problem.
Here is the specific code in question. It is located in the repaint method of my extension of JPanel. Don't bother looking at the various variables. its the commented line that I have a problem with. If I put it in place this code works, if I do not the last add line might add the label but it doesn't show up in the Panel.
Code:
//Label B -- The Label to be shown when Label A is clicked (called info) info.setBounds(originX+nations[INFO_PLACE].Xcord(year)/zoomFactor)+10, originY+(nations[INFO_PLACE].Ycord(year)/zoomFactor), info.getWidth(), info.getHeight()); //Label A -- the Label to be clicked, stored in an Array called nationLabels (changing its icon to the selected icon) nationLabels[INFO_PLACE].setIcon(nations[INFO_PLACE].image_selected(year)); //Set Label A to invisible //nationLabels[INFO_PLACE].setVisible(false); //Add label B this.add(info, -1); //Make label B visible (redundant) info.setVisible(true);
Finally, as a side note, I also have a slightly smaller problem.. if anyone knows how to fix it great. My zoom buttons only seem to work in the Panel which they affect. Once I move them to a separate Panel and call the zoom methods remotely, nothing happens. I have tried calling the repaint method in the zoom methods, and have also tried having the parent of the Panel to be zoomed to be repainted. Nothing. I can't even repaint the Panel remotely from a separate Panel, even though they are in the same Frame.
But as I said, my biggest problem is with the Label visibility problem.
Comment