views:

1283

answers:

3

I have many JLabels (which includes ImageIcons) in a JPanel.

And this JPanel is only a panel on the GUI; there are lots of other panels.

I want to place labels to the exact pixel coordinates on their JPanel container.

How can I do that without using GroupLayout?

+2  A: 

Either

Tom Hawtin - tackline
+5  A: 

See Doing Without a Layout Manager (Absolute Positioning) in the Java tutorials.

Creating a container without a layout manager involves the following steps.

  1. Set the container's layout manager to null by calling setLayout(null).
  2. Call the Component class's setbounds method for each of the container's children.
  3. Call the Component class's repaint method.
Michael Myers
+1  A: 

Take a look at MigLayout, which allows you to do absolute positioning, it's not part of the JDK, a seperate download from here:

http://www.miglayout.com/

It's very good as far as layout managers go and does absolute positioning, plus a whole load of other things.

Jon