use getBaseline(int w, int h) of a child component in the parent container
===

I have a custom swing component that has some child elements, including a JTextField. I want to give the container the same baseline as the JTextField, so I have overridden the getBaseline method in the container. But the position of the JTextField isn't always set when getBaseline is called for the container. I have tried to add a call to doLayout in the container's getBaseline method but that didn't help. What I want is the following:

    public int getBaseline(int w, int h) {
        Dimension size = textField.getPreferredSize();
        int textBaseline = textField.getBaseline(size.width, size.height);
        int textY = textField.getY();
        return textY + textBaseline;
    }

In the above code textY equals 0.