Java question: Can I draw a JLabel at a specified x,y coordinate?

duragezic

Lifer
Oct 11, 1999
11,234
4
81
I got this program due for school where I will be doing a GUI to implement the coding I've done previously. I made some pimp graphics in 'shop since I wanted things more interesting than a fillRect() or fillOval() etc! And I realize you need to add them to a JLabel as an ImageIcon. But I want to be able to draw these graphics at specified, and CHANGING x,y coordinates. They are located in a class which is a JPanel and thus I figured if only I could add the JLabels to the JPanel at specified spots just as you specify x,y coordinates when drawing a oval or whatever. Is this possible at all?! HOPEFULLY :disgust:



edit: Also, is there anyway I could get a JPanel to only have to hold one large JLabel that would wrap the text to a certain size?? Cause I'm running into the same problem with another part of the program. I need to output multiple lines and it'd be nice just to be able to concat a big string and display with a single JLabel in a JPanel.
 

duragezic

Lifer
Oct 11, 1999
11,234
4
81
Damn, seems like a lot of work, since there could be 10 or 20 labels to add, which are mostly in a Vector, but still, not sure if I totally get that.
 

duragezic

Lifer
Oct 11, 1999
11,234
4
81
Anyone know how I could implement that?? Right now I have a Display class that extends JPanel and in its paintComponent() method it draws an object on a specified, changing location then uses a for loop to go through a Vector of objects and draws them at specified (but these dont ever change) x,y location on the JPanel. I don't have any sort of main method like that link shows... it's all in the paintComponent. I don't understand on that link page what a pane or frame is.and how to apply it to mine.
 

duragezic

Lifer
Oct 11, 1999
11,234
4
81
Actually, NEVERMIND!

It noticed that a JPanel inherits setLocation methods according to Points or coordinates. So I got it working!
 

DanceMan

Senior member
Jan 26, 2001
474
0
0
Really, all of the functionality you need is found in directly subclassing off from JComponet, there is no need to either subclass from JPanel or JLabel. The label is providing you nothing except the JComponet for graphics displays.