PopupChooserBuilder () { if (myChooserComponent instanceof JList) { return new MyPopupChooserBuilder((JList)myChooserComponent); } else if (myChooserComponent instanceof JTree) { return new MyPopupChooserBuilder((JTree)myChooserComponent); } throw new IllegalStateException("Incorrect chooser component: " + myChooserComponent); }