Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an SSCCE.</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; class WhereIsMyComponent { public static void showComponentLocations(Container parent) { Component[] all = parent.getComponents(); System.out.println("Show locations of children.."); for (Component c : all) { System.out.println(c.getLocation()); } } public static void main(String[] args) { String msg = "Hello World!"; final JPanel p = new JPanel(new FlowLayout()); for (int ii=0; ii&lt;6; ii++) { p.add(new JLabel(msg)); } ComponentListener cl = new ComponentAdapter() { @Override public void componentResized(ComponentEvent ce) { showComponentLocations(p); } }; p.addComponentListener(cl); JFrame f = new JFrame("Where Is My Component?"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(p); f.pack(); f.setSize(400,300); f.setLocationByPlatform(true); f.setVisible(true); } } </code></pre> <h3>Typical output</h3> <pre><code>Show locations of children.. java.awt.Point[x=16,y=5] java.awt.Point[x=89,y=5] java.awt.Point[x=162,y=5] java.awt.Point[x=235,y=5] java.awt.Point[x=308,y=5] java.awt.Point[x=162,y=26] Show locations of children.. java.awt.Point[x=16,y=5] java.awt.Point[x=89,y=5] java.awt.Point[x=162,y=5] java.awt.Point[x=235,y=5] java.awt.Point[x=308,y=5] java.awt.Point[x=162,y=26] Show locations of children.. java.awt.Point[x=26,y=5] java.awt.Point[x=99,y=5] java.awt.Point[x=172,y=5] java.awt.Point[x=26,y=26] java.awt.Point[x=99,y=26] java.awt.Point[x=172,y=26] Press any key to continue . . . </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload