it's not nice but it's running:
public class Example extends JFrame {
private static JLabel a;
private static JLabel b;
public static void main(String[] args) {
Example example = new Example();
JPanel panel = new JPanel();
panel.setLayout(null);
a = new JLabel("a");
a.setBounds(50, 50, 10, 10);
b = new JLabel("b");
b.setBounds(150, 150, 10, 10);
panel.add(a);
panel.add(b);
example.getContentPane().add(panel);
example.setGlassPane(new MyGlas());
example.getGlassPane().setVisible(true);
example.setSize(400, 400);
example.setVisible(true);
}
public static class MyGlas extends JComponent {
public void paint(Graphics g) {
Rectangle aBounds = a.getBounds();
Rectangle bBounds = b.getBounds();
g.drawLine(aBounds.x, aBounds.y, bBounds.x, bBounds.y);
}
}
}