Why can’t I access my panel’s getWidth() and getHeight() functions?
Swing components have no width or height until they’ve been rendered. This occurs if you call pack() or setVisible(true) on a root container. Consider placing your x y int initialization code in the componentResized method of a ComponentListener that is added to your JPanel. e.g., import java.awt.event.*; import java.awt.*; import javax.swing.*; public class TestLinePanel { … Read more